-->
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 Collection Saving
PostPosted: Mon Jun 26, 2006 2:45 pm 
Newbie

Joined: Fri Jun 23, 2006 9:25 am
Posts: 10
Okay. Just like everyone here, I am a newbie.... I have a fairly simple problem and I hope someone can take a quick look at it and help me out. All that I am trying to do is to associate a SET of items to a User. I'm doing this via an Association Table though because the relationship is many-to-many.

What is going on currently is that the user information is saving correctly. However, the mapped table is never updated.


Thanks for any help you may offer!

Here are my files.
<b>
<hibernate-mapping>
</b>
<class name="com.hdms.sentinel.domain.duser.DUser" table="DUsers">

<id name="id" type="long" unsaved-value="null">
<generator class="native" />
</id>

<property name="username" />
<property name="firstName" />
<property name="lastName" />
<property name="title" />
<property name="email" />
<property name="enabled" />

<many-to-one name="userType" column="UserTypeId" cascade="save-update"
class="com.hdms.sentinel.domain.usertype.UserType" not-null="true" />

<set name="clients" table="DUserClientMap" lazy="false" cascade="save-update" >
<key column="DUserId"/>
<many-to-many column="ClientId" class="com.hdms.sentinel.domain.client.Client" />
</set>

</class>

<class name="com.hdms.sentinel.domain.client.Client"
table="Clients">

<id name="id" type="long" unsaved-value="null">
<generator class="native" />
</id>

<many-to-one name="plan" column="PlanId"
class="com.hdms.sentinel.domain.plan.Plan" not-null="true" />

<property name="name" />
<property name="shortName" />

<set name="users" table="DUserClientMap" lazy="false" cascade="save-update">
<key column="ClientId" />
<many-to-many column="DUserId"
class="com.hdms.sentinel.domain.duser.DUser" />
</set>

</class>
<b>
</hibernate-mapping>


DB Schema:
</b>
DROP TABLE IF EXISTS Clients ;
CREATE TABLE Clients
(
Id INTEGER NOT NULL AUTO_INCREMENT,
PlanId INTEGER NOT NULL REFERENCES Plans(Id),
Name VARCHAR(255) NOT NULL,
ShortName VARCHAR(255) NOT NULL,
LastEdited TIMESTAMP,
PRIMARY KEY (Id)
)ENGINE=InnoDB;

DROP TABLE IF EXISTS DUsers ;
CREATE TABLE DUsers
(
Id INTEGER NOT NULL AUTO_INCREMENT,
UserName VARCHAR(255) NOT NULL,
FirstName VARCHAR(255) NOT NULL,
LastName VARCHAR(255) NOT NULL,
Title VARCHAR(255) NOT NULL,
Email VARCHAR(255) NOT NULL,
UserTypeId INTEGER NOT NULL REFERENCES UserType(Id),
Enabled VARCHAR(255) NOT NULL,
LastEdited TIMESTAMP,
UNIQUE INDEX1 (UserName),
PRIMARY KEY (Id)
)ENGINE=InnoDB;


DROP TABLE IF EXISTS DUserClientMap ;
CREATE TABLE DUserClientMap
(
Id INTEGER NOT NULL AUTO_INCREMENT,
ClientId INTEGER NOT NULL REFERENCES Clients(Id),
DUserId INTEGER NOT NULL REFERENCES DUsers(Id),
LastEdited TIMESTAMP,
UNIQUE INDEX1 (ClientId, DUserId),
PRIMARY KEY (Id)
)ENGINE=InnoDB;


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.