This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
Before the object is persisted, all properties are populated except for both ids - autogenerated PKs, and internalId in the 2nd class - the foreign key - also null. When I try to persist the object, I get Seems like the ID value is not propagated down and INTERNAL_ID is never updated when the second class is persisted.
Could someone HELP please? I've been struggling with for more than 5 days already... I'm pretty sure it's something small and silly...
P.S. Weblogic 10, persistence provider - Kodo [ April 08, 2008: Message edited by: Dmitry Danilov ]
You have two mappings for the same column (INTERNAL_ID) both the Basic and the OneToOne. Ideally remove the Basic mapping/attribute. Otherwise you could try making the Basic read-only (insertable=false, updateable=false) to ensure the column is written from the OneToOne.
You could also ensure the internalId is set when you set the OneToOne, to do this you will need to first persist the target and call flush to assign the id. You could also use table sequencing and then you would not require calling flush.
Thanks James. It seems I've found the root of the evil - Kodo. It does not automatically propagate changes from one field in bidirectional relation to the other field unless you explicitly add Kodo's config property "kodo.InverseManager = true" in persistence.xml.
That problem is gone now, but another emerged - "Attempt to set column "ER_CORPORATE_EVENT_VERSIONS.INTERNAL_ID" to two different values: (class java.lang.Long)"268", (null)"null" This can occur when you fail to set both sides of a two-sided relation between objects, or when you map different fields to the same column, but you do not keep the values of these fields in synch."
I'm at a loss again. What might be the cause of this? I just don't see any obvious errors in the code...