Quantcast
Viewing all articles
Browse latest Browse all 128

spring-data-mongodb lazy loading question

when i use tree model like this:
Code:

       
@DBRef
private Menu parent;
@DBRef
private List<Menu> children = new ArrayList<Menu>();

and then i operate the domain like this:
Code:

Menu parent = menuService.find(parent);
child.setParent(parent);
child = menuService.upsert(child);
parent.addChild(child);
menuService.upsert(parent);

mongodb will use dbref to save the relationship of parent object and children.

if query parent by id. program will throws stack overflow error. i guess that is the @dbref injection in cycle.

so, how can i resolve this problem?

Viewing all articles
Browse latest Browse all 128

Trending Articles