-->
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: Extra select when inserting entity with lazy many-to-one rel
PostPosted: Tue May 06, 2008 4:05 am 
Newbie

Joined: Thu Jan 13, 2005 4:04 am
Posts: 12
Location: Estonia
Hi,

Does anybody know is there some alternative way (compared with session.load(SomeProxy.class, id)) to force Hibernate to avoid extra select when inserting entity with many-to-one lazy relation.

I bring following abstract example:

public class A {
private B b;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "b_id", nullable = false)
public B getB() {
return b;
}

...

}


When inserting (saving) A with new B() injected into (manually through bean setter) with it's proper id value set, then hibernate generates extra select statement for "B" each time before insert statement is executed for A.

From Hib tips-and-tricks documentation I found solution for a problem: http://www.hibernate.org/118.html#A20

But is'nt there any other and more elegant way (not call session.load each time I really know ID of related object) to avoid extra select for described situations. Through some tricky annotation I do not know or smth else?

I found also similar topic from forum with no any suggestions available to get over of the problem:

http://forum.hibernate.org/viewtopic.ph ... ert+select

Thnks,
Ilhan


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.