-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: @SecondaryTable: primary record already exists?
PostPosted: Wed Aug 26, 2009 4:14 pm 
Beginner
Beginner

Joined: Thu Dec 29, 2005 12:08 pm
Posts: 31
Location: Acton, MA
I have an entity that spans two tables, primary_table and secondary_table. I've annotated it properly with the @SecondaryTable annotation.

It just so happens that in my database, primary_table has more records in it than secondary_table.

Another way to think of this is that the primary_table does not just store instances of my entity, but instances of other objects as well.

At any rate, if I create a new instance of my entity, and set its @Id to a value that exists in the primary table, I am pleased to see that Hibernate recognizes that oh, hey, there's a primary_table record in there already, so it does an INSERT on the secondary_table, as it should, and an UPDATE on the primary_table. Everything is fine.

My problem is actually...well, Hibernate is the only JPA provider that does this. The other two (of the Big Three) both attempt blind INSERTs into the primary table. When that @Id value exists in the primary_table, then of course the transaction rolls back with a primary key violation.

My question is: is this a known optimization taken by Hibernate--i.e. this is a problem that the authors foresaw and solved? Or is this just happy chance? The specification as far as I can tell is somewhat quiet on this point. I'd be curious to get any pointers or answers related to this subject.

Thanks very much,
Laird


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.