[Hibernate] problems with cascade

2007-11-21 Thread Ingo Villnow




Hello,

i have the following problem. i have a table "projects" and a table
"managers" with a i think called "1:N" relationship.

My mapping file (partly):

hibernate-mapping
    class name="Project" table="Project"
    set name="managers" inverse="true" cascade="all"
    key
    column name="Projectid" not-null="true" /
    /key
    one-to-many class=".Manager" /
    /set
    /class
/hibernate-mapping

Now i want to delete all my managers concerning one special project and
add the new manager. So I do the following:

Manager manager;
ProjectDAO dao = new ProjectDAO();
Project project = (Project) dao.getSession().get(Project.class,
projectID);
Set managers = project.getManagers();
managers.clear();
manager = new Manager();
manager.setEmployee(employee_manager);
manager.setFunction(managerFunction);
manager.setProject(project);
dao.getSession().save(manager);
managers.add(manager);
project.setManagers(managers);
dao.save(project);

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?

Thank you very much!!!

Greetings from Berlin!

Ingo


begin:vcard
fn:Ingo Villnow
n:Villnow;Ingo
org:University of Applied Sciences Berlin;Applied Computer Sciences
adr:;;Treskowalle 8;Berlin;Berlin;10318;Deutschland
email;internet:[EMAIL PROTECTED]
title:Student der FHTW Berlin
tel;work:+49 30 267 42675
tel;home:+49 30 497 87 432
tel;cell:+49 176 23 37 59 49
x-mozilla-html:TRUE
url:http://www.fhtw-berlin.de
version:2.1
end:vcard

-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/___
hibernate-devel mailing list
hibernate-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/hibernate-devel


Re: [Hibernate] problems with cascade

2007-11-21 Thread Massip, Etienne
No a hibernate member, but maybe cascade=all, delete-orphan could do the 
trick ?



De : [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] De la part de Ingo Villnow
Envoyé : mercredi 21 novembre 2007 11:05
À : hibernate-devel@lists.sourceforge.net
Objet : [Hibernate] problems with cascade


Hello,

i have the following problem. i have a table projects and a table managers 
with a i think called 1:N relationship.

My mapping file (partly):

hibernate-mapping
class name=Project table=Project
set name=managers inverse=true cascade=all
key
column name=Projectid not-null=true /
/key
one-to-many class=.Manager /
/set
/class
/hibernate-mapping

Now i want to delete all my managers concerning one special project and add the 
new manager. So I do the following:

Manager manager;
ProjectDAO dao = new ProjectDAO();
Project project = (Project) dao.getSession().get(Project.class, projectID);
Set managers = project.getManagers();
managers.clear();
manager = new Manager();
manager.setEmployee(employee_manager);
manager.setFunction(managerFunction);
manager.setProject(project);
dao.getSession().save(manager);
managers.add(manager);
project.setManagers(managers);
dao.save(project);

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?

Thank you very much!!!

Greetings from Berlin!

Ingo

-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/___
hibernate-devel mailing list
hibernate-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/hibernate-devel


Re: [Hibernate] problems with cascade

2007-11-21 Thread Massip, Etienne
Did you try to set cascade to the value I mentioned in my previous post ? The 
project entry should not be deleted, if that's what you meant.



De : Ingo Villnow [mailto:[EMAIL PROTECTED] 
Envoyé : mercredi 21 novembre 2007 11:20
À : Massip, Etienne
Objet : Re: [Hibernate] problems with cascade


If I delete the entry in the project-table than the childs will be deleted, 
to.. that's all fine. But i only want to delete the children, without deleting 
the parent entry, for example project.getManagers().clear() - The problem is 
that it would be hard to find all manager-elements by projectid and to delete 
them one by another. Is there an easier way? 

thanks


2007/11/21, Massip, Etienne [EMAIL PROTECTED]: 

No a hibernate member, but maybe cascade=all, delete-orphan could do 
the trick ?



De : [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] De la part de Ingo 
Villnow
Envoyé : mercredi 21 novembre 2007 11:05
À : hibernate-devel@lists.sourceforge.net
Objet : [Hibernate] problems with cascade



Hello,

i have the following problem. i have a table projects and a table 
managers with a i think called 1:N relationship.

My mapping file (partly):

hibernate-mapping
class name=Project table=Project
set name=managers inverse=true cascade=all
key
column name=Projectid not-null=true /
/key
one-to-many class=.Manager /
/set
/class
/hibernate-mapping

Now i want to delete all my managers concerning one special project and 
add the new manager. So I do the following:

Manager manager;
ProjectDAO dao = new ProjectDAO();
Project project = (Project) dao.getSession().get(Project.class, 
projectID);
Set managers = project.getManagers();
managers.clear();
manager = new Manager();
manager.setEmployee(employee_manager);
manager.setFunction(managerFunction);
manager.setProject(project);
dao.getSession().save(manager);
managers.add(manager);
project.setManagers(managers);
dao.save(project);

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?

Thank you very much!!!

Greetings from Berlin!

Ingo



-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
hibernate-devel mailing list
hibernate-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/hibernate-devel 






-- 
Liebe Grüße

Ingo

sites:
http://www.herrgustav.de
http://www.myspace.com/herrgustav 
http://www.myspace.com/mrvill  
mailto:
[EMAIL PROTECTED] - [EMAIL PROTECTED] - [EMAIL PROTECTED] 
-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/___
hibernate-devel mailing list
hibernate-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/hibernate-devel


[Hibernate] unsubscribe

2007-11-21 Thread Shardayyy

-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/___
hibernate-devel mailing list
hibernate-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/hibernate-devel