-->
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: how to ppopulate (non FK)columns in many-to-many?
PostPosted: Wed Aug 22, 2007 8:00 am 
Newbie

Joined: Wed Aug 22, 2007 7:37 am
Posts: 1
As discussed in hibernate docs (7.5.3. many to many in http://www.hibernate.org/hib_docs/refer ... tions.html) the mapping for a bidirectional many-to-many table is :

<class name="Person">
<id name="id" column="personId">
<generator class="native"/>
</id>
<set name="addresses" table="PersonAddress">
<key column="personId"/>
<many-to-many column="addressId"
class="Address"/>
</set>
</class>

<class name="Address">
<id name="id" column="addressId">
<generator class="native"/>
</id>
<set name="people" inverse="true" table="PersonAddress">
<key column="addressId"/>
<many-to-many column="personId"
class="Person"/>
</set>
</class>

where PersonAddress table holds the relationship bet Person and Addres using foriegn keys. It is with the assumption that table definitions are something like :

create table Person ( personId bigint not null primary key )
create table PersonAddress ( personId bigint not null, addressId bigint not null, primary key (personId, addressId) )
create table Address ( addressId bigint not null primary key )

Now, my question would be, how do I create my mapping if I have the following table definition for PersonAddress?

create table PersonAddress ( personAddressId bigint not null, personId bigint not null, addressId bigint not null, other string not null, primary key (personAddressId) )

How do I set values to columns "personAddressId" and "other" such that when I save the Person or Address data, corresponding entries will be created in the PersonAddress.

Ive tried searching for samples of such case but all I can see are examples that only contain 2 foreign keys in link table of a many-to-many mapping(such as the one on top).


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.