java - mapping two fields from one table on to other -


i have these 2 tables

users(    id pk,    name varchar(30) ); 

the other table is

orders(   id pk,   orderby fk users.id,   orderto fk users.id ); 

now, want create orders entity class maps orderby , orderto user. thing confuse cascading should use.

class orders{    ///    @manytoone(fetch = fetchtype.lazy    @joincolumn(name="orderby")    users orderby;     ///    @manytoone(fetch = fetchtype.lazy    @joincolumn(name="orderto")    users orderto;  } 

i thinking create 2 fields in users table such that

class account{     ///     @onetomany(fetch = fetchtype.lazy)     @joincolumn(name="orderto")     list<orders> ordersreceived;      ///     @onetomany(fetch = fetchtype.lazy)     @joincolumn(name="orderbo")     list<orders> ordersplaced;  } 

but again, not sure cascading shall use. users table populated other processes orders has nothing with. don't want when placing order, particular transaction should add/delete anything. however, might need update specific field of user whenever place order.

i'll suggest avoid use cascade @ (if possible)... when place order, should follow following steps:

1) load user database

2) create order ...

3) linkup order user (this is, order.setorderby(user))

4) persist order entitymanager.

5) change user attribute.

from experience, cascade should used carefully. used persist entities in 1 shoot (cascade.persist) (example: persisting newly user new entities orders)


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -