-->
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: Defining/Adding to the primary key of a map
PostPosted: Tue Aug 15, 2006 11:47 am 
Newbie

Joined: Mon Nov 21, 2005 6:06 pm
Posts: 4
Is there a way to add to the default primary key definition of a map using a 'unique-key' tag or something of that nature? By default, hibernate uses the 'key' and 'map-key' tags to create the primary key index. I would like to include one additional field in that primary key.

For example, I have a class called EAccount that can be used for either Email or IMPP. I have another 'Person' class that has maps of both email and impp accounts (e.g. Map emailAccounts = new HashMap()). I would like to use the same database table to store both email and impp accounts. My mappings are as follows:

Code:
<class name="Person" table="person">
    ...

    <map name="emailAccounts" table="eaccount">
        <key column="person_id"/>
        <map-key column="type" type="string"/>
        <composite-element class="EAccount">
            <property name="address"/>
            <property name="accountType" column="account_type" type="EAccountUserType"/>
        </composite-element>
    </map>

    <map name="imppAccounts" table="eaccount">
        <key column="person_id"/>
        <map-key column="type" type="string"/>
        <composite-element class="EAccount">
            <property name="address"/>
            <property name="accountType" column="account_type" type="EAccountUserType"/>
        </composite-element>
    </map>

    ...
</class>


Is there a way to specify that the 'accountType' property be included in the primary key?

I realize that it's a simple enough task to write the SQL creation script for that table myself but I would prefer to allow Hibernate to take care of that particular detail.
Code:


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 15, 2006 4:54 pm 
Newbie

Joined: Fri Jun 09, 2006 8:03 am
Posts: 12
Instead of using map-key you can use <composite-map-key>

however the <key> can only have one column.


Top
 Profile  
 
 Post subject: Try <formula>
PostPosted: Tue Sep 05, 2006 5:00 pm 
Beginner
Beginner

Joined: Mon Aug 15, 2005 10:20 am
Posts: 32
Location: Brazil
Maybe <formula> does what you want. This article has a nice explanation on formula usage.


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.