aspose file tools*
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
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "hibernate association delete" Watch "hibernate association delete" New topic
Author

hibernate association delete

siraj baig
Ranch Hand

Joined: Jul 11, 2006
Posts: 42
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

Joined: Feb 05, 2001
Posts: 17260
    
    6

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


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: http://aspose.com/file-tools
 
subject: hibernate association delete