-->
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: Unnecessary fetch on insert
PostPosted: Tue Jun 21, 2011 7:36 am 
Newbie

Joined: Tue Jun 21, 2011 7:05 am
Posts: 1
I have the following scenario:
  • I have two entity classes: X and Y. X has a @ManyToOne association to Y which is not cascaded.
  • I create an (unmanaged) instance x of X and an (unmanaged) instance y of Y, and fill the reference to y in x.
  • Entity y already has a corresponding row in the underlying database, but entity x is new.
  • I persist entity x.

When I perform this scenario, I expect to see one query: INSERT x. However, what actually happens is that Hibernate performs TWO queries:
  • SELECT y
  • INSERT x

Furthermore, I also notice that after the persist of x, the reference to y does not actually become managed and there is no instance of Y in the session! So, why is the SELECT on y performed at all? Is there a way to prevent this?


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.