Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Entity Fetch Graphs(Bidirectional Entities and Fetch Graph Behavior)
Entity Fetch Graphs [message #1690055] Tue, 24 March 2015 20:58
Will Dazey is currently offline Will DazeyFriend
Messages: 10
Registered: February 2015
Junior Member
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?
Previous Topic:JAXB marshalling performance with nested classes
Next Topic:Getting Configuration error. Class [drive-class] not found intermittently
Goto Forum:
  


Current Time: Mon Mar 04 15:15:30 GMT 2024

Powered by FUDForum. Page generated in 0.02188 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top