-->
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: additional properties in many-to-many association table??
PostPosted: Fri May 18, 2007 4:38 pm 
Newbie

Joined: Fri May 18, 2007 4:22 pm
Posts: 3
Hi,

I'm having a lot of trouble figuring out the mapping needed for this setup. I've looked through FAQs, tutorials, and searched the forums with no luck (although I wouldn't be surprised if a similar issue has already been answered).

Basically, what I want is a many-to-many relationship where the association table stores additional information (e.g. Is_Historical, below).


Here's the setup:
desired SQL tables:

Feature (table)
----------
Feature_ID (PK) int
...
...


FeaturePlaceName (table)
----------
Feature_ID (FK) int
PlaceName_ID (FK) int
Is_Historical


PlaceName (table)
----------
PlaceName_ID (PK) int
PlaceName (Unique) string


desired Java classes (only two). The Feature.Set<PlaceName> represents the many-to-many, but the individual field PlaceName._isHistorical is stored in the association table.

Feature (class)
----------
int _id
Set<PlaceName> _names
...


PlaceName (class)
----------
int _id
String name
boolean _isHistorical
...


Any help or links to similar issues would be appreciated! Thanks!!

Dave


Last edited by dpdearing on Fri May 18, 2007 5:30 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Fri May 18, 2007 5:30 pm 
Newbie

Joined: Fri May 18, 2007 4:22 pm
Posts: 3
Well, I think I just stumbled across something that is working, but it may not be the prettiest way. It also doesn't have all of the PK compositions that I'd like.

I had to add an extra class (Name.java) just to wrap a String in order to map it to its own table.

The remaining problem is that the FeaturePlaceName table doesn't have the composite PK of Feature_ID (FK) and Name_ID (FK) that I'd like. Any idea how I can accomplish this?

Mappings:
Code:
    <class name="Feature" table="Feature">
        <id name="id" column="Feature_ID">
            <generator class="native"/>
        </id>
        <set name="names" table="FeaturePlaceName"
            cascade="save-update">
            <key column="Feature_ID"/>
            <one-to-many class="PlaceName"/>
        </set>
    </class>

    <class name="PlaceName" table="FeaturePlaceName">
        <id name="id" column="PlaceName_ID">
            <generator class="native"/>
        </id>
        <property name="isHistorical" column="Is_Historical"/>
        <many-to-one name="name" class="Name"
            column="name" cascade="save-update" fetch="join"/>
    </class>

    <class name="Name" table="PlaceName">
        <id name="name"/>
    </class>


Thanks again!
Dave


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 19, 2007 6:45 pm 
Newbie

Joined: Fri May 18, 2007 4:22 pm
Posts: 3
Well, I think I finally answered my own question. The above guess is somewhat incorrect.

The answer that I needed and was digging for is provided in the Hibernate "Example: Various Mappings" for Customer/Order/Product. I just hadn't used the right combination of terms when searching.

http://www.hibernate.org/hib_docs/refer ... derproduct

Hope this is helpful to anyone else with a similar problem!


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.