• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

hibernate association delete

 
siraj baig
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • 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
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks Mark.

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