Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] Re: SecondaryTable mapping question

On Wed, Aug 26, 2009 at 2:05 PM, Laird Nelson <ljnelson@xxxxxxxxx> wrote:
What if--this is hypothetical for this example, but realistic for other similar ones--what if a row already exists in the id_rec table with, say, a pk of 5, and I insert a new Person whose primary key ("id") is set to 5?  Is EclipseLink smart enough to realize that it should do an "upsert" on the id_rec table?  Or will it try, blindly, to slam two INSERTS home, thus causing the transaction to roll back?

Turns out it does a blind INSERT.  So does OpenJPA.  Hibernate is the only one that handles this scenario flawlessly.

The question I guess is: should it?

This is not the case of having a primary record whose secondary record may not exist.  That's well documented, and you can work around it (at least in Hibernate; possibly in EcliseLink as well) with custom annotations or descriptor customizers and so on.

This is, instead, the case of having "too many" primary records.  That is, you're guaranteed you're going to have a secondary record, but the related primary record might already be there, so a merge() or a persist() of the mapped object will need to result in different SQL for each table.

As far as I can tell, the specification is silent here.  Any thoughts are welcome.

Best,
Laird

Back to the top