-->
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: many-to-many update
PostPosted: Fri Oct 08, 2004 6:30 am 
Newbie

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

we have a many to many asso. from contact to receiverlist. and both are in a many to one asso. to user. means a user can have many receiverlists and many contacts. and a contact can belong to may receiverlists and inverse.

if we now make a update in our receiverlist. e.g. add a new contact to the receiverlist. in the tables it will be updated. also in the "consists_of" table
( m2m tablename). but if we load the new receiverlist, it wont be updated in our jsp view...

some one's got an idea.. or need some code snippets?


THX A LOT

receiverlist.hbm.xml:
...
<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>

...

contact.hbm.xml:

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


show_recieverlist.jsp:

<%@ page language="java" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@page import="user.*, receiverlist.*, java.util.*"%>

<%
User user = (User) session.getAttribute("user");
if (user == null)
{
%>
<h1><bean:message key="error.login"/></h1>
<p><a href='<%= response.encodeURL("view/login/login.jsp")%>'>
<bean:message key="link.login"/></a><p>
<%
return;
}
String receiverlist_id = request.getParameter("receiverlist_id");
Set receiverlists = user.getReceiverlists();
Iterator iter = receiverlists.iterator();
Receiverlist receiverlist = (Receiverlist)iter.next();
while(receiverlist.getReceiverlist_id() != Integer.parseInt(receiverlist_id))
{
if(iter.hasNext())
{
receiverlist = (Receiverlist)iter.next();
}
else
{
%>
<p><bean:message key="error.receiverlist"/></p>
<%
return;
}
}
Set contacts = receiverlist.getContacts();

%>
<h1><bean:message key="home.title"/>
<bean:write name="user" property="firstname"/>
<bean:write name="user" property="name"/></h1>
<h2><bean:message key="receiverlist.title"/></h2>
<logic:iterate id="contactsIter" collection="<%= contacts %>">
<bean:write name="contactsIter" property="firstname"/>
</logic:iterate>


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.