Bug 137 : NullPointerException in IdBinderSimple.convertSetId for Postgres
Priority 
High
Reported Version 
 
Logged By 
Rob
Status 
Fixed
Fixed Version 
2.1.0
Assigned To 
 
Product 
Ebean - core
Duplicate Of 
 
Created 
12/08/2009
Updated 
12/08/2009
Type 
Bug
 
Attachments 
No attachments

Hi,

I'm trying to upgrade from 1.0.2 to 2.0.2. When I save an object
(using postgresql), I get:

java.lang.NullPointerException
at com.avaje.ebean.server.deploy.id.IdBinderSimple.convertSetId
(IdBinderSimple.java:91)
at com.avaje.ebean.server.deploy.BeanDescriptor.convertSetId
(BeanDescriptor.java:1120)
at com.avaje.ebean.server.persist.DefaultPersister.setIdGenValue
(DefaultPersister.java:708)
at com.avaje.ebean.server.persist.DefaultPersister.insert
(DefaultPersister.java:255)
at com.avaje.ebean.server.persist.DefaultPersister.saveVanilla
(DefaultPersister.java:235)
at com.avaje.ebean.server.persist.DefaultPersister.save
(DefaultPersister.java:211)
at com.avaje.ebean.server.persist.DefaultPersister.saveRecurse
(DefaultPersister.java:176)
at com.avaje.ebean.server.persist.DefaultPersister.save
(DefaultPersister.java:161)
at com.avaje.ebean.server.core.DefaultServer.save(DefaultServer.java:
1147)
at com.avaje.ebean.server.core.DefaultServer.save(DefaultServer.java:
1137)
at com.avaje.ebean.Ebean.save(Ebean.java:520)
at ...

 
Rob 12 Aug 18:46
Yes, this is a postgres specific bug.

Yes, this is a postgres specific bug.

1. The IdType is GENERATOR and should be SEQUENCE - for Postgres83Platform.getDbIdentity().getIdType()

2. Also note with postgres the ebean.columnAliasPrefix has to be "as c" rather than "c" ... as postgres needs the "as" keyword for column alias'.

In ebean.properties you need to have:
ebean.columnAliasPrefix=as c


Workaround:

If you are initialising programmatically you can do:

// as alternative to putting this in ebean.properties
GlobalProperties.put("ebean.columnAliasPrefix", "as c");

// set the IdType to SEQUENCE
Postgres83Platform pg = new Postgres83Platform();
pg.getDbIdentity().setIdType(IdType.SEQUENCE);

ServerConfig c = new ServerConfig();
c.setName("pgtest");
c.loadFromProperties();
c.setDatabasePlatform(pg);
c.setDefaultServer(true);
c.addClass(TOne.class);
...

EbeanServerFactory.create(c);


You can't set the IdType via ebean.properties at the moment which is a bit of a shame.

Rob 12 Aug 19:05
Fixed in HEAD

I have fixed this in HEAD.

I have uploaded a snapshot build with this fix included.
This should be downloadable from sourceforge:

https://sourceforge.net/projects/ebeanorm/files/

at...

ebean/2.0.2/snapshot/ebean-2.0.2-postgresfix.jar

Rob 12 Aug 19:51
ebean-2.0.2-snapshot-postgresfix.jar

Re-organised the folders in sourceforge.

Uploaded the snapshot containing this postgres fix as:

ebean-2.0.2-snapshot-postgresfix.jar

woResponse

Upload a file