-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: deleting many-to-many association ???
PostPosted: Thu Oct 19, 2006 10:48 am 
Beginner
Beginner

Joined: Thu Aug 03, 2006 3:43 am
Posts: 45
OK so here is the problem: I have a many to many association between ProjectProfile and DeveloperProfile.... I am aware that there are allot of posts regarding many-to-many associations but I can't seem to find the answer to a simple question:

how can I delete just the association between a project and a developer(in my case)

thank you


Hibernate version:
3.1.2

Mapping documents:
<hibernate-mapping
>
<class
name="net.sourceforge.lebon.model.DeveloperProfile"
table="DeveloperProfile"
>

<id
name="id"
column="ID"
type="java.lang.Long"
>
<generator class="assigned">
<param name="sequence">DEVP_SEQ</param>
<!--
To add non XDoclet generator parameters, create a file named
hibernate-generator-params-DeveloperProfile.xml
containing the additional parameters and place it in your merge dir.
-->
</generator>
</id>

<timestamp
name="modifiedAt"
column="modified_at"
access="property"
unsaved-value="null"
/>

<set
name="projects"
table="DeveloperWork"
lazy="true"
cascade="save-update"
sort="unsorted"
>

<key
column="developer_id"
>
</key>

<many-to-many
class="net.sourceforge.lebon.model.ProjectProfile"
column="project_id"
outer-join="auto"
/>

</set>
............

<hibernate-mapping
>
<class
name="net.sourceforge.lebon.model.ProjectProfile"
table="ProjectProfile"
>

<id
name="id"
column="ID"
type="java.lang.Long"
>
<generator class="assigned">
<param name="sequence">PRP_SEQ</param>
<!--
To add non XDoclet generator parameters, create a file named
hibernate-generator-params-ProjectProfile.xml
containing the additional parameters and place it in your merge dir.
-->
</generator>
</id>

<timestamp
name="modifiedAt"
column="modified_at"
access="property"
unsaved-value="null"
/>

<set
name="developers"
table="DeveloperWork"
lazy="true"
cascade="save-update"
sort="unsorted"
>

<key
column="project_id"
>
</key>

<many-to-many
class="net.sourceforge.lebon.model.DeveloperProfile"
column="developer_id"
outer-join="auto"
/>

</set>
...........

Name and version of the database you are using:
HSQLDB


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 19, 2006 11:04 am 
Newbie

Joined: Wed Oct 18, 2006 1:28 pm
Posts: 3
Something like this =)

Code:
DeveloperProfile.getProjects ().remove(project);
DAO.update(DeveloperProfile);


Maybe you have to make it at the other side too, depends of your mapping
Hope I could help =)


Last edited by maddonde on Thu Oct 19, 2006 12:49 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 19, 2006 11:16 am 
Beginner
Beginner

Joined: Thu Aug 03, 2006 3:43 am
Posts: 45
ok... fair enough...

but I tried that with the save method below and it didn't work :(

Code:
    public void save(final E entity) {
        HibernateCallback callback = new HibernateCallback() {
            public Object doInHibernate(Session session) throws HibernateException {
                BaseEntity savedEntity = (BaseEntity) session.merge(entity);
                entity.setModifiedAt(savedEntity.getModifiedAt());
                entity.setModifiedBy(savedEntity.getModifiedBy());
                return null;
            }
        };
        getHibernateTemplate().execute(callback);
    }


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 24, 2006 6:33 am 
Beginner
Beginner

Joined: Thu Aug 03, 2006 3:43 am
Posts: 45
update:

in the end I made an SQL query to solve this.. It's not the best way to go but I can't find any other solution... If anybody has any ideas I am opened to suggestions...

Thank You


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.