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.
|