Comments are available to members only. Sign up or Log in to view these comments.
Main Topics
Browse All Topics
I have a many to many relationship between groups and users that I have mapped as shown at the bottom of this post. I now would like to add an additional column to the user_group database, which would need to be reflected in the set element that I use in both group and user hibernate-mappings to keep track of their many-to-many relationship as is shown below. Unlike the user_id and group_id, the third column is not part of the primary key. This column happens to be a status_id column which is a foreign key to the status table which contains status names such as "active"/ "inactive." (it's keyed by status_id, of course). So in the the context of my user/group relationship, this additional column would provide me with a way of signifying that a given user is no longer in a given group without having to delete a row from the user_group table.
How would I map that third column in hibernate?
Firstly, here's my hibernate.cfg.xml
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 2.0//EN"
"http://hibernate.sourcefo
<hibernate-configuration>
<session-factory>
<!-- properties -->
<property name="connection.username"
<property name="connection.url">jdbc
<property name="dialect">net.sf.hibe
<property name="connection.password"
<property name="connection.driver_cl
<!-- mapping files -->
<mapping resource="com/talisen/work
<mapping resource="com/talisen/work
</session-factory>
</hibernate-configuration>
Then here's my User.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourcefo
<hibernate-mapping package="com.talisen.workf
<class name="User" table="user">
<id name="userId" column="USER_ID" type="java.lang.Integer">
<generator class="increment"/>
</id>
<property name="userName" column="USER_NAME" type="java.lang.String" not-null="true" />
<set name="groups" table="user_group" inverse="true">
<key column="user_id" />
<many-to-many column="group_id"
class="com.talisen.workflo
</set>
</class>
</hibernate-mapping>
And here's my Group.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourcefo
<hibernate-mapping package="com.talisen.workf
<class name="Group" table="groupyo">
<id name="groupId" column="GROUP_ID" type="java.lang.Integer">
<generator class="increment" />
</id>
<property name="groupName" column="GROUP_NAME"
type="java.lang.String" not-null="true" />
<property name="groupDesc" column="GROUP_DESC"
type="java.lang.String" not-null="true" />
<set name="users" table="user_group">
<key column="group_id" />
<many-to-many column="user_id"
class="com.talisen.workflo
</set>
</class>
</hibernate-mapping>
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: TimYatesPosted on 2005-01-28 at 01:26:29ID: 13161253
Comments are available to members only. Sign up or Log in to view these comments.