I am looking at an EntityGraph use case with the following entities in a bidirectional relationship:
@Entity
public class Parent implements Serializable{
@Id @GeneratedValue @Column(name="PARENT_ID")
private int id;
@Version
private int version;
@Basic(fetch = FetchType.EAGER)
@Column(name="PARENT_AGE")
private int age;
@OneToMany (mappedBy="parent", fetch=FetchType.LAZY)
private Collection<Child> children;
}
@Entity
public class Child implements Serializable{
@Id @GeneratedValue @Column(name="CHILD_ID")
private int id;
@Version
private int version;
@Basic(fetch = FetchType.EAGER)
@Column(name="CHILD_AGE")
private int age;
@ManyToOne(fetch = FetchType.LAZY)
private Parent parent;
}
I then create an EntityGraph like so:
EntityGraph<Parent> eg = em.createEntityGraph(Parent.class);
eg.addAttributeNodes("children");
eg.addSubgraph("children", Child.class).addAttributeNodes("parent");
em.getTransaction().begin();
Query query = em.createQuery("SELECT a FROM Parent a", Parent.class);
query.setHint("javax.persistence.fetchgraph", eg);
Parent parent = (Parent) query.getResultList().get(0);
The result of this case is that the parent entity has the attribute "age" loaded, such that emf.getPersistenceUnitUtil().isLoaded(parent, "age") == true. Is this a supported use case for entity graphs with EclipseLink? Am I missing a step to inform EclipseLink that this relationship is bidirectional?