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.  [ 3 posts ] 
Author Message
 Post subject: Mapping fields from JOIN table...
PostPosted: Tue Apr 03, 2007 5:40 pm 
Newbie

Joined: Tue Apr 03, 2007 10:43 am
Posts: 6
My setup is below. I'm wondering how I can setup a mapping document given the table definitions I have. As you see the JOIN table gems_partner_activity table contains partner_id and activity_id, so that I can specify a bi-directional relationship for both partner and activity relationships (Partner has Activities and Activities have Partners defined).

In addition, however, there are three values in the JOIN table ( hold_transmission, transmit_realtime, and scheduler_name), which belong exclusively to the unique combination of partner and activity combination and they do not make sense outside of that relationship.

How do I create a mapping file to propertly represent them in a Domain Object Model that will be generated?

Here is my setup:

Hibernate version 3.2

DB is MySQL41

Table definitions DDL:
# Partner table definition
CREATE TABLE gems_partner (
partner_id INTEGER NOT NULL,
name VARCHAR(255) NOT NULL,
PRIMARY KEY (partner_id)
);

CREATE TABLE gems_activity (
activity_id INTEGER NOT NULL,
name VARCHAR(255) NOT NULL,
fullpath VARCHAR (255) NOT NULL,
PRIMARY KEY (activity_id)
);

# This is the JOIN table for Activity and Partner
CREATE TABLE gems_partner_activity (
partner_id INTEGER NOT NULL,
activity_id INTEGER NOT NULL,
hold_transmission boolean,
transmit_realtime boolean,
scheduler_name varchar(255),
PRIMARY KEY (partner_id, activity_id),
FOREIGN KEY (partner_id)
REFERENCES gems_partner(partner_id),
FOREIGN KEY (activity_id)
REFERENCES gems_activity(activity_id),
INDEX partner_ind(partner_id),
INDEX activity_ind(activity_id)
);


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 04, 2007 2:46 am 
Beginner
Beginner

Joined: Thu Feb 01, 2007 3:08 am
Posts: 20
U can use the below mapping in gemspartner.


mapping of gemspartner

<bag name="links" table="gems_partner_activity" cascade="none">

<column name="partner_id" not-null="true" unique="true" />
</key>
<composite-element class="gemspartneractivity ">
<parent name="partner_id"/>
<property name="hold_transmission" type="string" column="hold_transmission" />
<many-to-one name="activity_id" entity-name="gemsactivity " cascade="none" >
<column name="activity_id" not-null="true" length="30"/>
</many-to-one>
</composite-element>
</bag>

check the model classew also ...

class gemspartner
{
private int partnerid;
private String name;
private Collection links;//collection of ggemspartneractivity objects
//getter and setter
}
class gemsactivity
{
private ... activity_id;
.....
....

private Collection links;//collection of gemspartneractivity objects
//getter and setter
}
class gemspartneractivity
{
private gems_partner part;
private gemsactivity act;
private boolean hold_transmission;
private boolean transmit_realtime;
//getter and setter
}


PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject: Good...
PostPosted: Mon Apr 09, 2007 2:49 pm 
Newbie

Joined: Tue Apr 03, 2007 10:43 am
Posts: 6
This should work for me - thanks.

James


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

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.