-->
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: Foreign key within Composite ID = Repeated column in mapping
PostPosted: Sun Nov 18, 2007 5:25 pm 
Newbie

Joined: Sun Nov 18, 2007 4:57 pm
Posts: 5
So I've been searching for hours how to fix this legacy problem:

I have two physical tables, but 3 domain objects. Here are my tables (They have been simplified):
Account
Account Number (PK)

User
Account Number (PK)
User ID (PK)

Product Use (We will not need to look at this one)
Product Id (PK)
User ID
Account Number
Usage
Product Name

User and Product Use are all from the same table. I need to use Account Number and User ID as primary keys of User because the same user id is used for multiple accounts (legacy!).

Here is what my mapping looks like so far:
Code:
<class name="Account" table="ACCOUNT">
     <id name="accountNumber" column="ACCOUNT_NUMBER"></id>

     <bag name="users" lazy="true" inverse="false" table="BIG_TABLE">
        <key column="ACCOUNT_NUM" not-null="true" />
        <one-to-many class="User"/>
     </bag>
</class>

......

<class name="User" table="BIG_TABLE">
     <subselect>
        select distinct USER_ID, ACCOUNT_NUM
        from BIG_TABLE
     </subselect>
     <composite-id>
        <key-property name="userId" column="USER_ID" />
        <key-property name="accountNumber" column="ACCOUNT_NUM" />
     </composite-id>
...
  </class>


This fails, giving me a "Repeated column mapping for entity: User" error.

The problem is trying to use a field mapped as my composite key (User) as a foreign key (Account bag).
How would I get around this? Please remember I'm unable to change anything on the database side of things.

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 19, 2007 12:59 pm 
Newbie

Joined: Sun Nov 18, 2007 4:57 pm
Posts: 5
So....
I guess a view of the table?
Two columns for account number to avoid mapping it twice?

Thoughts?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 09, 2007 11:56 am 
Newbie

Joined: Sun Apr 04, 2004 4:22 am
Posts: 7
Code:
<class name="Account" table="ACCOUNT">
     <id name="accountNumber" column="ACCOUNT_NUMBER"></id>

     <bag name="users" lazy="true" inverse="false" table="BIG_TABLE">
        <key>
           <column="ACCOUNT_NUM" not-null="true" />
           <column="USER_ID"  not-null="true" />
        </key>   
        <one-to-many class="User"/>
     </bag>
</class>


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.