Bug 65 : BeanPropertyAssocOne not initialized
Reported Version 
Logged By 
Fixed Version 
Assigned To 
Ebean - core
Duplicate Of 
No attachments

For some reasons it seems the BeanPropertyAssocOne.initialize() has not been called and so subsequent access to the targetDescriptor results in an NullPointerException.

I am pretty sure this is not the right patch, but for me it started to work afterwards. Still, as I wrote this might just be a hack.
I am still learning the "in depths" of this framework.

Index: ../ebean/src/com/avaje/ebean/server/deploy/BeanPropertyAssocMany.java
--- ../ebean/src/com/avaje/ebean/server/deploy/BeanPropertyAssocMany.java (revision 127)
+++ ../ebean/src/com/avaje/ebean/server/deploy/BeanPropertyAssocMany.java Sat Feb 14 10:37:23 CET 2009
@@ -310,6 +310,11 @@
if (uids.length == 1 && uids[0].isEmbedded()) {

BeanPropertyAssocOne one = (BeanPropertyAssocOne) uids[0];
+ if (one.getTargetDescriptor() == null)
+ {
+ // I'll consider this as a hack ...
+ one.initialise();
+ }
BeanDescriptor targetDesc = one.getTargetDescriptor();
BeanProperty[] emIds = targetDesc.propertiesBaseScalar();
for (int i = 0; i < emIds.length; i++) {
Index: ../ebean/src/com/avaje/ebean/server/deploy/BeanPropertyAssoc.java
--- ../ebean/src/com/avaje/ebean/server/deploy/BeanPropertyAssoc.java (revision 127)
+++ ../ebean/src/com/avaje/ebean/server/deploy/BeanPropertyAssoc.java Sat Feb 14 12:40:30 CET 2009
@@ -264,6 +264,11 @@
} else {
// embedded id
BeanPropertyAssocOne embProp = (BeanPropertyAssocOne)props[0];
+ if (embProp.getTargetDescriptor() == null)
+ {
+ // I'll consider this as a hack ...
+ embProp.initialise();
+ }
BeanProperty[] embBaseProps = embProp.getTargetDescriptor().propertiesBaseScalar();
ImportedIdSimple[] scalars = createImportedList(owner, cols, embBaseProps);

Rob 16 Feb 08:17
The issue here...

The issue here is:
- You have a entity bean with an EmbeddedId property
- It also has a OneToMany property

When BeanDescriptor initialises its properties ... it needs to make sure that it initialises the EmbeddedId property *BEFORE* the OneToMany property.

At the moment BeanDescriptor does not garuntee the order... and so you can get the NPE if the OneToMany property initialises before the EmbeddedId property.

Rob 16 Feb 09:26
I can reproduce

It looks to be as I thought. I can reproduce the NPE.

Exception in thread "main" java.lang.ExceptionInInitializerError
at main.FindCMaster.main(FindCMaster.java:14)
Caused by: java.lang.NullPointerException
at com.avaje.ebean.server.deploy.BeanPropertyAssocMany.createExported(BeanPropertyAssocMany.java:314)
at com.avaje.ebean.server.deploy.BeanPropertyAssocMany.initialise(BeanPropertyAssocMany.java:148)

The order of the properties is maintained so if you put the @EmbeddedId property AFTER the @OneToMany property in the java source code you will get this error - and moving the @EmbeddedId property above the @OneToMany in the java source code will get around this issue (you won't get the NPE).

public class CMaster {

String dcol;

List details;

CMasterId id;

Rob 16 Feb 09:29
And the fix

And the fix is to The BeanDescriptor initialise() method:

// always initialise the Id properties first
BeanProperty[] idProps = propertiesId();
for (int i = 0; i < idProps.length; i++) {

// now initialise all the non-id properties
Iterator it = propertiesAll();
while (it.hasNext()) {
BeanProperty prop = it.next();
if (!prop.isId()){

Rob 16 Feb 09:31
Fixed in v1.0.3

Fixed in v1.0.3

Rob 17 Feb 11:12

In testing with Bug66 etc ... this fix needed to change (as it didn't take into account imported properties).

So, the fix is now a 2 phase initialisation of the entity beans ... 1st phase initialises the ID properties and the second phase initialises the rest (including all the associated properties which need the imported and exported properties to already be initialised).

Rob 17 Feb 11:12
Still fixed in v1.0.3

Just to be clear - still fixed in v1.0.3 though.


Upload a file