File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Object Relational Mapping and the fly likes hibernate association delete Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "hibernate association delete" Watch "hibernate association delete" New topic

hibernate association delete

siraj baig
Ranch Hand

Joined: Jul 11, 2006
Posts: 42
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
Dept dept = new Dept();
dept.setEmpList(empList)//after removing 2 rows.;
After if i save dept, the removed employees are still in db.
How to delete these employees from database.

Mark Spritzler

Joined: Feb 05, 2001
Posts: 17271

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.


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
siraj baig
Ranch Hand

Joined: Jul 11, 2006
Posts: 42
Thanks Mark.

I am using cascade='all'. Now i replaced to cascade='all,delete-orphan', It works.
I agree. Here's the link:
subject: hibernate association delete
It's not a secret anymore!