java - How do I Iterate Tree data? -
when query data base using
list<textualreq> textualreqlist = session.createquery("from textualreq parent null").list();
here textualreq object
@id @generatedvalue( generator = "increment" ) @genericgenerator( name = "increment", strategy = "increment" ) @column(name="id") private int id; @manytoone @joincolumn(name="parent") private textualreq parent; @onetomany( mappedby = "parent", cascade = cascadetype.all, fetch = fetchtype.eager ) @column(name="children") private set<textualreq> children = new hashset<textualreq>(); @column(name="data") private string data;
i think should it!
public void displaydata(){ display(null); } public void display(textualreq textualreq){ list<textualreq> textualreqlist = null; string parentid = "is null"; if(textualreq!=null){ parentid = "= "+textualreq.id; system.out.println(textualreq.data); system.out.print(" "); } textualreqlist = session.createquery("select * textualreq parent "+parentid).list(); if(textualreqlist==null) return; for(int i=0;i<textualreqlist.size();i++){ display(textualreqlist.get(i)); } }
just call function displaydata().
Comments
Post a Comment