开发者

How could I decide how much data to load in JPA?

I have a database with nodes that points to other nodes in parent children relationship and a lookup table to translate between web addresses and nodes.

I need to get information about the node and it's parents and children but each time I fetch a node through the lookup table it only loads the data related to that node (name etc.) is there any way of go past this lazy loading and fetch more data?

My data structures:

NodeLookup: 
    long id;   
    Str开发者_如何转开发ing url;  
    Node node;  

Node:  
    long id;  
    String name;  
    List<Node> parents; //@ManyToMany  
    List<Node> childrens; //@ManyToMany  

Now I solve it by fetching a node through the NodeLookup table and use the node's id to fetch the node for real but that seems like a waste of resources.

(I'm using the play framework)


By default JPA use lazy load for relations. If you want load the relations when you load the node, you must use eager load :

@ManyToMany(fetch=FetchType.EAGER)
List<Node> parents;

@ManyToMany(fetch=FetchType.EAGER
List<Node> childrens;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜