Hibernate JPA - ManyToOne relationship not populated

I am currently moving a (working) application using EclipseLink in Hibernate JPA, basically it went pretty smoothly, but I find one that I can’t explain, and also can’t come up with a good condition search!

Basically, I have four objects with one-to-many relationships forming a chain:

EntityA has an EntityB list, each of which has an EntityC list, each of which has an EntityD list

each of them has a many-to-one relationship going the other way, therefore:

EntityD has EntityC, which has EntityB, which has EntityA.

This (greatly reduced for clarity):

@Entity
public class EntityA {
  @OneToMany (cascade = CascadeType.All, mappedBy = "entityA")
  private List<EntityB> entityBList;
  ...
}

@Entity
public class EntityB {
  @OneToMany (cascade = CascadeType.All, mappedBy = "entityB")
  private List<EntityC> entityCList;

  @JoinColumn (name = "ENTITY_A", referencedColumnName = "ENTITY_A_ID")
  @ManyToOne (cascade = CascadeType.PERSIST, optional = false)
  private EntityA entityA;
}

@Entity
public class EntityC {
  @OneToMany (cascade = CascadeType.ALL, mappedBy = "entityC")
  private List<EntityD> entityDList;

  @JoinColumn (name = "ENTITY_B", referencedColumnName = "ENTITY_B_ID")
  @ManyToOne (cascade = CascadeType.PERSIST, optional = false)
  private EntityB entityB;
}

@Entity
public class EntityD {
  @JoinColumn (name = "ENTITY_C", referencedColumnName = "ENTITY_C_ID")
  @ManyToOne (cascade = CascadeType.PERSIST, optional = false)
  private EntityC entityC;
}

EntityA ( ) , , EntityA, PersistentBag List<EntityB>. , , List<EntityB> EntityCs EntityB.

, , EntityA, B C, , EntityD EntityC , null.

- , EntityA, , EntityC, "entityDList", null.

, , :

EntityManager.refresh(entityC);

, PersistentBag entityDList.

, , Hibernate 2 ( 3, , ), , , . -?

- , .refresh? - , Hibernate ?

+6
3

, , , , .

, , , max_fetch_depth, - ( max_fetch_depth, ?).

, @OneToMany - , , , , , , , Hibernate 1 , , , . , , .

- , , , , .

+3

. - . → B- > C- > D, , D. - .

"from A left join fetch B left join fetch C left join fetch D"

C- > D ? , ...

+1

The hibernate docs say you can set it using the hibernate.max_fetch_depth property. The default value is 3. You can find it in the "Hibernate Reference Documentation" on page 47.

+1
source

All Articles