-->
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.  [ 1 post ] 
Author Message
 Post subject: Deleting rows in many to many relationship
PostPosted: Mon Mar 01, 2010 5:31 am 
Newbie

Joined: Mon Mar 01, 2010 4:34 am
Posts: 1
Hello, I´m a newbie to Hibernate so please be patient.
My situation is as follows:

I have a N to M relation between tables Profile and Element. In the database there is an intermediate table element_profile. The mapping of this in hibernate is:

<class name="ProfileVO" table="profile">
<id name="code" column="codprofile" />
<property name="description" column="desprofile" />

<set fetch="join" name="elements" table="elemento_perfil" lazy="false">
<key column="codprofile" />
<many-to-many column="codelement" class="ElementVO" />
</set>

</class>

<class name="ElementVO" table="element">
<id name="code" column="codelement" />
<property name="description" column="deselement" />
<property name="codigoElementParent" column="codeleparent" />

<set fetch="join" name="profiles" table="element_profile" lazy="false">
<key column="codelement" />
<many-to-many column="codprofile" class="ProfileVO" />
</set>

<set inverse="true" name="elements">
<key column="codeleparent" />
<one-to-many class="ElementVO" />
</set>

</class>


All the queries I have done work perfectly, but I can´t get the Set of elements of the actual profile.., (My idea: Get the profile, get Set of elements, Iterate elements and if an element is an element to be deleted I save it in a vector, I remove from profile elements marked as deleted).

begin();

ProfileVO proflle=dao.load(getSession(), codeProfile);
Set elements =profile.getElementos(); <====================It has no elements!!!



Iterator itr = elements.iterator();
Vector vDelete=new Vector();
while(itr.hasNext()){
ElementVO element = (ElementVO)itr.next();
if(element.getCode().equalsIgnoreCase(codeElement)){
vDelete.add(element);
}
}
if(vDelete.size()>0){
profile.getElements().removeAll(vDelete);
}


commit();

What am i doing wrong? Is there other way of doing this??

Thank you in advance.


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

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.