I'm using JPA 2 and Hibernate 3. I noticed that calling EntityManager.merge() causes a SELECT on every referenced entity in the object graph PLUS inner joins between some of them.
Suppose you want to merge() a FooBar.
@Entity
public class FooBar {
@ManyToOne
private Foo foo;
@ManyToOne
private Bar bar;
}
@Entity
public class Foo {
@ManyToOne
private Baz baz;
}
@Entity
public class Bar {
@ManyToOne
private Baz baz;
}
If you do, Hibernate will issue a SELECT for each of FooBar, Foo, and Bar, and two for Baz. Then, it will issue a SELECT for Foo joined with Baz and another for Bar joined with Baz. Since I just wanted to merge a FooBar, I was expecting a single SELECT from it, but I ended up with a whopping 7 SELECT's!
First of all, is this normal? Second, if it is, is there a way to issue just a single SELECT?
Thanks.