java - Working with Hibernate relationships -



java - Working with Hibernate relationships -

i'm working in hibernate. got 3 entities, that's relationship among them:

user 1 -> n orders 1 -> n order details

how add together row in table "order details" of specific order given user?

i know how add together new row in table orders , order details, that:

user user=(user)session.get(user.class, username); order order=new order(); orderdetails orderdetails=new orderdetails(); orderdetails.setamount(1); order.addorderdetails(orderdetails); user.addorder(order); session.save(user); transaction.commit();

it correct?

but happen when want add together row in table addorderdetails of specific order given user? this?

list<order> o=session.createcriteria(order.class) .add( restrictions.eq("iduser", user) ); o.get(0).addorderdetails(orderdetails);

actually don't know how work tables orders , orders details, should user table? how? using criteria user table can list of users, can not work others tables.

thanks

if have mapping represents relationship, can user , user have set or list elements of type order. can update specific order.

methods have described right short of mistakes (call list() on criteria list example).

java hibernate

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -