Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] Performance problem with hierarchical tree structure (JPA)

Hi,

 

I have a performance issue that I hope to receive some advice on. I know that one of the major benefits with EclipseLink is its ability to tune the generated selects, and I need some help with the following case.

 

Iv created a small test case to illustrate the problem.

 
I have two classes which represents a hierarchical tree structure. The "Tree" class contains one top Node and each node may contain zero or more child nodes.

 

@Entity
public class Tree {
   
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
   
    @Version
    private Long version;
   
    @Basic
    private String name;
   
    @OneToOne(cascade = CascadeType.ALL)
    private Node top;
   
    ...
    ...
   
}

 

@Entity
@Table(name = "NODE")
public class Node extends Tree {
   
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
   
    @Version
    private Long version;
   
    @Basic
    private String name;
   
    @Basic
    private String xyz;
   
    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    private List<Node> childNodes;
   
    ...
    ...
    ...
}

 


I have the following JPQL query;

 


    <query>select t
           from Tree t
           where t.name = ?1
    </query>
   

 

When issuing the query EclipseLink generates the following queries (assuming that nothing is in the cache).

 

1. On query to get the Tree object.
2. On query to get the Top Node object.
3. Then one query for each Node in the tree structure to get the nodes children.

 


I have tried to use different types of hints, e.g. eclipselink.join-fetch, but without any luck.
The below hint just caused a null pointer exception.

 

  <named-query name="treeQuery">
    <query>select t
           from Tree t
           where t.name = ?1
    </query>
    <hint name="eclipselink.join-fetch" value="t.top.childNodes"/>

 

 </named-query>

 


What am i doing wrong. Is there a way to achieve this without eclipslink generating so many queries?

 


Please help:-)

 


Best regards,
Rune


Back to the top