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