I use JPA 2 and Hibernate 3. I noticed that calling EntityManager.merge() calls SELECT for each reference object in the PLUS object graph the internal connections between some of them.
Suppose you want to combine () 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. He will then release SELECT for Foo, connected to Baz, and another for Bar, connected to Baz. Since I just wanted to combine FooBar, I expected one SELECT from it, but I got a huge amount of 7 SELECT!
First of all, is this normal? Secondly, if so, is there a way to release only one SELECT?
Thanks.
source share