From: Ingo V. <ing...@go...> - 2007-11-21 10:04:44
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> </head> <body bgcolor="#ffffff" text="#000000"> Hello,<br> <br> i have the following problem. i have a table "projects" and a table "managers" with a i think called "1:N" relationship.<br> <br> My mapping file (partly):<br> <font face="Courier New"><br> <hibernate-mapping><br> <class name="....Project" table="Project"><br> <set name="managers" inverse="true" cascade="all"><br> <key><br> <column name="Projectid" not-null="true" /><br> </key><br> <one-to-many class=".....Manager" /><br> </set><br> </class><br> </hibernate-mapping></font><br> <br> Now i want to delete all my managers concerning one special project and add the new manager. So I do the following:<br> <font face="Courier New"><br> Manager manager;<br> ProjectDAO dao = new ProjectDAO();<br> Project project = (Project) dao.getSession().get(Project.class, projectID);<br> Set managers = project.getManagers();<br> <b>managers.clear();</b><br> manager = new Manager();<br> manager.setEmployee(employee_manager);<br> manager.setFunction(managerFunction);<br> manager.setProject(project);<br> <b>dao.getSession().save(manager);<br> managers.add(manager);</b><br> </font><b><font face="Courier New">project.setManagers(managers);<br> dao.save(project);</font><br> </b><br> But the thing is that only the new manager was added. The other database entries were not deleted. I thought, if i update the parent entry (project) the child entrys will be deleted automatically (project.getManagers.clear()). Where is my problem? Can anybody help?<br> <br> Thank you very much!!!<br> <br> Greetings from Berlin!<br> <br> Ingo<br> </body> </html> |