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