orm - Hibernate does't update joined collection -
i have employee entity (employee(id,name,company_id)):
@entity public class employee { @id @column(name="id") private integer id; @manytoone(fetch = fetchtype.eager, cascade=cascadetype.all) @joincolumn(name = "company_id") private company company; ... }
and have company entity (company(id,name)):
@entity public class company { @id @column(name="id") private integer id; @onetomany(fetch=fetchtype.eager, cascade=cascadetype.all) @joincolumn(name="company_id") @where(clause="status_code = '1'") private set<employee> employeeset; ... }
a company can have more employees, 1 employee belongs 1 company @ time. joined them (i want employees status 1) , set cascade all, when update employee @ company employeeset in company doesn't refresh, nor old neither new company. update method employee:
sessionfactory.getcurrentsession().merge(employee);
i tried update(employee) too, no success. miss code?
first, employeeset
mapping wrong. change to
@onetomany(fetch=fetchtype.eager, cascade=cascadetype.all, mappedby = "company") @where(clause="status_code = '1'") private set<employee> employeeset;
second, need handle other side of relation well, meaning need add employee new company's employeeset
, remove old one. necessary in order maintain consistency of companies loaded hibernate session.
Comments
Post a Comment