Bug 399 : Deleting a bean without an @Id field causes SQL syntax error
Priority 
Medium
Reported Version 
 
Logged By 
Philippe Gassmann
Status 
Fixed
Fixed Version 
2.8.1
Assigned To 
 
Product 
Ebean - core
Duplicate Of 
 
Created 
12/05/2012
Updated 
12/05/2012
Type 
Bug
 
Attachments 
No attachments

Here are my two beans:

@Entity
public class TestUser extends Model {
@Id
public String id;
}

@Entity
public 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.

 
Rob 14 Jun 11:53
Fixed in HEAD

Fixed in HEAD

woResponse

Upload a file