users@glassfish.java.net

Re: Toplink NullPointerException with compound primary key?

From: <glassfish_at_javadesktop.org>
Date: Wed, 10 Sep 2008 12:44:15 PDT

Well, I can't work around this issue. :-( Anyone know why Toplink is giving me a NullPointerException?

A related question: it would appear that Toplink grabs an autogenerated ID (whether from a sequence, or an autonumber column, or a table) and uses it only in the INSERT statement. Why doesn't it first set the primary key value on the about-to-be-persisted object?

What I mean is, suppose I'm putting a Foo in the database, and its ID attribute is its primary key, and it has been set to have a @GenerationType of IDENTITY. On SQL Server, Toplink does [i]not[/i] do a SELECT @@IDENTITY and then call setID() on the object prior to inserting it. Why not? Instead it simply takes the [i]state[/i] out of the about-to-be-persisted Foo object, augments it with the identity value, and, presumably, only calls setID() on the Foo object [i]after[/i] insertion.

My object graph in my previous message needs to be able to access that generated ID [i]before[/i] the persist occurs in order to work: that is, I need to make sure that the ID that my PartyEntity class [i]will[/i] have is available to the new, about-to-be-persisted instance of my PartyNameBinding class. I don't see a way to get that.

This is, incidentally, a problem that's already solved--just not here. That is, the JOINED database inheritance strategy has to solve this problem--the subtype table usually has a primary key that is a foreign key to the supertype table, so if the supertype table uses an IDENTITY generation strategy, then why can't Toplink do the same sort of thing here?
[Message sent by forum member 'ljnelson' (ljnelson)]

http://forums.java.net/jive/thread.jspa?messageID=298433