Here are my two beans:
@Entitypublic class TestUser extends Model { @Id public String id;}
@Entitypublic class TestRelation extends Model {
@Constraints.Required @ManyToOne(cascade = CascadeType.ALL) public TestUser from; @Constraints.Required @ManyToOne(cascade = CascadeType.ALL) public TestUser to; @Constraints.Required public String qualifier;}
Test code: TestUser u1 = new TestUser(); u1.id = "1"; TestUser u2 = new TestUser() ; u2.id = "2"; u1.save(); u2.save(); TestRelation relation = new TestRelation(); relation.from = u1; relation.to = u2; relation.qualifier = "foo"; relation.save(); relation.delete();
Deleting the relation bean throw a MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'and qualifier='foo' and from_id='1' and to_id='2'' at line 1
The generated mysql statement is: "delete from test_relation where and qualifier='foo' and from_id='1' and to_id='2'"
Obviously adding an id field on the TestRelation object fixes the issue.
Fixed in HEAD