java - Hibernate example with multiple 1 to many mappings needed -


been looking on , can't find example of this.. new hibernate can create single level json... can make happen if use prepared statements , multiple arrays, can't work using hibernate , createsqlquery.

i need create json multiple 1 many levels, ie:

{ "success": true, "count": 1, "message": "", "data": [

{ "inprogress" : false, "item" : "372", "time" : "09:00", "date" : "2013-03-22", "status" : "inprogress",

"labels" : [ "first", "second", "third", “last” ],

"item" : [ { "rank" : "1st", “time”: “6:36:05”,

"details" : [ { "interval" : "1:31.63" },

{ "interval" : "1:32.63" },

{ "interval" : "1:35.99" },

{ "interval" : "1:38.63" } ] } ] } ] }

so there can multiple details in multiple items , there multiple labels.

            query query = session.createsqlquery(sql)                     .addscalar("item",hibernate.string)                     .addscalar("time",hibernate.string)                     .addscalar("date",hibernate.string)                 .addscalar("futureprogression",hibernate.string)              .setresulttransformer(transformers.aliastobean(abc.class));              resultlist = query.list(); 

i can create top level, can't figure out how use .addentity insert entities level...

anyone have example handy?

thanks, jeff

go through below link see how define 1-to-many relationship mappings

http://docs.jboss.org/hibernate/orm/3.3/reference/en-us/html/example-parentchild.html

if persist top level object set of lower level objects, hibernate take care of creation of top level , lower level entries in table.

session.save(parent)


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -