java - Hibernate 3.6 customize the setter of one to many mapping -
i have simple @onetomany
mapping:
public class member(){ .... @onetomany(fetch = fetchtype.lazy, mappedby="member", orphanremoval=true) private list<user> users; @transient private user firstuser; ... public setusers(list<user> users){ //if(users.size() > 0) this.firstuser = users.get(0); this.users = users; } } public class user(){ ..... @manytoone @joincolumn(name = "user_id") private member member; }
here i'd set this.firstuser = users.get(0)
if mapped users length greater 0. doesn't work if put code directly setter
method commented line in member
, example, read member object users
size 5, tried print firstuser
, firstuser
still null, expected result should users.get(0)
.
any idea?
you try following:
public class member(){ .... @onetomany(fetch = fetchtype.eager, mappedby="member", orphanremoval=true) private list<user> users; @transient private user firstuser; ... public setuser(list<user> users){ if(users.size() > 0) this.firstuser = users.get(0); this.users = users; } @postload public void settransientuser() { this.setusers(this.users); } }
Comments
Post a Comment