Bug 122 : Entity with no @Id ... can return null
Priority 
High
Reported Version 
 
Logged By 
Rob
Status 
Fixed
Fixed Version 
2.0.0
Assigned To 
 
Product 
Ebean - core
Duplicate Of 
 
Created 
10/06/2009
Updated 
10/06/2009
Type 
Bug
 
Attachments 
No attachments

create table Test(id integer primary key, value varchar(20))

@Entity
@Table(name="test")
public class Test {
// @Id
private int id;
private String value;
/*
the setter and getter ??????
*/
}


TestCase:
public void testGetAllTests() {
List<Test> tests = Ebean.find(Test.class).findList();
assertEquals(2,tests.size());
assertNull(tests.get(0));
assertNull(tests.get(1));
}

Note the List containing nulls.

Similar issue can occur with @SqlSelect on an entity with no @Id defined.

 
Rob 10 Jun 00:05
Refer to example

http://docs.google.com/Doc?id=ddh2svk9_59gfsrgsgk

Documented Testcase .

Rob 10 Jun 00:09
Initial thoughts...

Thanks. This is a good bug.

... I'll have a look in more detail later but my initial thoughts are ...

Any @Entity without an @Id has a couple of issues.

1. It can't be persisted by default (no insert/update/delete support)
2. It can't be effectively put/get from the "Persistence Context"

The issue around SqlTreeNodeBean.load()
... is that the code is assuming the entity has an Id (to see if it is already in the persistence context already and hence won't be loaded/populated from the resultSet).

... aka the nulls in the list are result of this incorrect assumption / bug (there is no Id but it is not already in the persistence context - and never will be because it will never have an id).

So, I'll have to look in more detail... but I'm thinking if an Entity doesn't have a @Id .. I need to handle these issues in SqlTreeNodeBean... and also in the persistence logic.


There may be some special handling for SqlSelect ... but I'll need to look at that.


Cheers, Rob.

littleJava 29 Jun 06:54
New URL

http://docs.google.com/View?id=ddh2svk9_59gfsrgsgk
The url is better, everyone can access it.

woResponse

Upload a file