-->
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: Mapping a table with a collection to itself
PostPosted: Sat Dec 18, 2010 5:20 pm 
Newbie

Joined: Sat Dec 18, 2010 3:45 pm
Posts: 1
The entity i want is this:
Code:
class ExternalAccounts {
  private String externalAccountType; // part of key
  private String externalAccountId;  // part of key
  private Set<Integer> accountIds; // collection of account ids
}


My table "external_account" looks like:

external_account_type(string), external_account_id(string), account_id(integer)

Clearly i can have many different accounts for a particular "key" (ie, externalAccountType + externalAccountId).

The mapping i tried:
Code:
<class name="ExternalAccounts" table="external_account">
   <composite-id>
     <key-property name="externalAccountType" column="external_account_type" />
     <key-property name="externalAccountId" column="external_account_id" />
   <composite-id>

   <set name="accountIds" table="external_account">
      <key>
          <column name="external_account_type"/>
          <column name="external_account_id"/>
      </key>
      <element column="account_id" type="integer"/>
    </set>
</class>


But i get a "multiple entries with the same key" error when i try to load an ExternalAccounts object. I of course just set the externalAccountType and externalAccountId and pass that in to the "load" method. The error does make sense, and i can "fix" this by using a 2nd table; but i'd rather not.

Is there a mapping that will get me what i want?

Thanks.


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.