• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

hibernate association delete

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI,
i have two tables 1.dept and 2. emp
i am using 1-many association to retrieve the data.
assume hql: select * from dept where deptno=10;
when i run this hql query
assume: i am getting 1 row of dept data and
associated 5 rows of emp data.
Now i am removing 2 rows from emp list.And assigning the emp list to dept
like:
Dept dept = new Dept();
dept.setEmpList(empList)//after removing 2 rows.
sesion.save(dept);
After if i save dept, the removed employees are still in db.
How to delete these employees from database.

Thanks,
siRaj
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is you cascade option? Are you just using "all" or "delete" I think you want to use "all, delete-orphan"

With just "delete" it will keep the record in the database but it will just null out the FK field.

Mark
 
siraj baig
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Mark.

I am using cascade='all'. Now i replaced to cascade='all,delete-orphan', It works.
 
reply
    Bookmark Topic Watch Topic
  • New Topic