-->
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.  [ 2 posts ] 
Author Message
 Post subject: Hibernate Table Per Class & Set Mapping
PostPosted: Thu Oct 04, 2012 11:12 am 
Newbie

Joined: Mon Apr 02, 2007 12:53 pm
Posts: 10
Hi,

I'll illustrate my issue with a contrived example to try and keep it as simple and easy to follow as possible. However my real issue is in legacy code and so I cannot change the schema or anything like that.

I have a table per class hiarachy in my code. Lets say Customer1 and Customer2. They have unique discriminator values (1 and 2 respecitivly). Each customer can may have 0 or more addresses. The addresses are stored in a single table. This table stores the reference to the customer id and the customer discriminator value. In the address mapping I have:

<any name="customer" meta-type="CustomerMetaType" id-type="long">
<column name="customerid" not-null="true" />
<column name="discriminator" not-null="true" />
</any>

This is fine. However in my customer1 and customer2 mappings I have:

<set name="addresses" outer-join="false">
<key column="customerid"/>
<one-to-many class="Address"/>
</set>

This has the issue that loading customer1 with id 1 would pick up any addresses for customer2 with id 2. My initial attempt at a fix was to add multiple keys to the set:

<key>
<column name="customerid"/>
<column name="discriminator"/>
</key>

However when doing that I get the following exception:

org.hibernate.MappingException: Foreign key (FKE3DB9024789337A4:edge_clientstate [gametype,gameid])) must have same number of columns as the referenced primary key (edge_game_fixedodds [id])

Does anyone have a solution to this. Is there a way of mapping the descriminator to the class as some sort of virtual composite key? Or is there something else I can do with the set mapping to restrict it to the specific customer table?

Thanks,

Sam


Top
 Profile  
 
 Post subject: Re: Hibernate Table Per Class & Set Mapping
PostPosted: Fri Oct 05, 2012 5:46 am 
Newbie

Joined: Mon Apr 02, 2007 12:53 pm
Posts: 10
Solved!

Code:
<set name="addresses" outer-join="false" where="discriminator='customer1'">


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.