-->
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: object / table relation update problem
PostPosted: Mon Oct 11, 2004 4:15 am 
Newbie

Joined: Wed Oct 06, 2004 3:20 am
Posts: 12
HI!

does someone else already had the Problem, that after an update, the table row is OK, but in my Object, it isn't updated? how can i solve that? do i have to call that explicit?

cheers


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 11, 2004 5:57 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
not enough info, but i may be a problem of java integrity (that is a code problem), are you using bidirectionnal association?

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 11, 2004 7:34 am 
Newbie

Joined: Wed Oct 06, 2004 3:20 am
Posts: 12
yes i use bidirectional assosiations.

a bidirectional many2many from contact to receiverlist. and we would like to get, that if i delete a contact, this should be deleted in all receiverlists. but not inverse. logicaly:-) do you need some more infos?

here some code:

contact.hbm.xml:

<class name="contact.Contact" table="contact">
<id name="contact_id" type="int" unsaved-value="null" >
<column name="contact_id" sql-type="integer" not-null="true"/>
<generator class="identity"/>
</id>
...
<many-to-one name="user" column="u_id" class="user.User"/>
<set name="receiverlists" table="consists_of" cascade="save-update" inverse="true">
<key column="contact_id"/>
<many-to-many class="receiverlist.Receiverlist" column="receiverlist_id"/>
</set>

</class>


receiverlist.hbm.xml


<class name="receiverlist.Receiverlist" table="receiverlist">
<id name="receiverlist_id" type="int" unsaved-value="null" >
<column name="receiverlist_id" sql-type="integer" not-null="true"/>
<generator class="identity"/>
</id>
...
<many-to-one name="user" column="u_id" class="user.User"/>

<set name="contacts" table="consists_of" cascade="save-update" >
<key column="receiverlist_id"/>
<many-to-many class="contact.Contact" column="contact_id" />
</set>

</class>



the file where we would like to delete a contact :...and i'm sure, its not that f. complicated....:-)
with this file we have to delete the deleted contact in the receiverlists. but i think that should be done automatically by hibernate...



public class DeleteContactAction extends Action{

public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse res) throws Exception{

List temp = Collections.synchronizedList(new ArrayList());
DynaActionForm df = (DynaActionForm)form;
String[] contactId = (String[])df.get("deleteContact");
HttpSession session = req.getSession(true);
User user = (User)session.getAttribute("user");

for(int i=0; i < contactId.length; i++){
Set contactSet = user.getContacts();
Iterator contactIter = contactSet.iterator();

for(int m=0; m < contactSet.size(); m++){
Contact contact = (Contact)contactIter.next();
if(contact.getContactId() == Integer.parseInt(contactId[i])){
Deleter.delete(contact);
temp.add(contact);
}
}
}


Iterator tempIter = temp.iterator();
for(int n = 0; n < temp.size(); n++){
Contact c = (Contact)tempIter.next();
user.getContacts().remove(c);
Set receiverlistSet = user.getReceiverlists();
Iterator receiverlistIter = receiverlistSet.iterator();
for(int r=0; r < receiverlistSet.size(); r++){
Receiverlist receiverlist = (Receiverlist)receiverlistIter.next();
receiverlist.getContacts().remove(c);
}
}

return mapping.findForward("contactDeleted");
}
}


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 11, 2004 8:03 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
you have to manage both ends of the association.
For this, the best practice is to have removeChild and addChidl methods in which you set the parent and the child ends of the association.
If you have hibernate in action, it is very well explained

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


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.