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

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -