I have between a simple @OneToMany
man
and pet
entities:
to @OneToMany (mappedBy = "owner", cascade = CascadeType.ALL, bringing = FetchType.EAGER) public set & lt; Pet & gt; GetPets () {Return pets; }
I man
s associated with would load the pet
s why I came up with this (in a test group) :
@RunWith (@ SpringJUnit4ClassRunner.class) @ContextConfiguration public class AppTest {@Test @Rollback (wrong) @ Tronsacjinl (only = false reading) public void testApp () {CriteriaBuilder qb = Em.getCriteriaBuilder (); CriteriaQuery & LT; Person & gt; C = qb.createQuery (person. Class); The root of the & lt; Person & gt; P1 = C. From (Person. Class); Setozoin & lt; Person, pet & gt; Join = P. 1. Joint (Person_pets); TypedQuery & LT; Person & gt; Q = em.createQuery (c); & Lt; Person & gt; Person = q.getResultList (); For (person page: individuals) {System.out.println (p.getName ()); (Pet pet: p.getPets ()) {System.out.println ("\ t" + pet.getNick ()); However, by changing the SQL logging on show, it performs three questions (DB contains 2 person). Hibernate: join select individual Kid Person0_ inner id0_, name0_ as person0_.name, person0_.id = pets1_ Pet as sex0_ as person0_.sex person. owner_id hibernate pets1_: pets0_.owner_id choose as owner3_0_1_, then id1_ as pets0_.id, as pets0_.id id1_0_ ,, nick1_0_ as pets0_.nick pets pets0_.owner_id as owner3_1_0_ the pets0_ where pets0_.owner_id =? Hibernate: pets0_.owner_id choose as owner3_0_1_, id1_ as pets0_.id, nick1_0_ as id1_0_ as pets0_.id, pets0_.nick, pets pets0_.owner_id as owner3_1_0_ the pets0_ where pets0_.owner_id =?
Any suggestions given?
Thanks Gergo
Instead Someone should write
Setjoin & lt; Person, stomach & gt; Join = P Lkjoind (Prson_pets);
p1.fetch (Person_.pets);
Comments
Post a Comment