-->
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.  [ 4 posts ] 
Author Message
 Post subject: same column in multiple composite foriegn keys : supported?
PostPosted: Mon Aug 15, 2005 6:30 pm 
Newbie

Joined: Mon Aug 15, 2005 3:55 pm
Posts: 2
We have a situation where a table, Type1, has multiple composite foriegn keys to other tables but where one of the columns is repeated across those foriegn keys: is this
supported by Hibernate?

<class name=Type1 table="Type1" mutable="true">
<id name="id" column="id" type="java.lang.Integer"/>
<property name="property1" column="property1" />
<property name="property2" column="property2" />
<many-to-one name="foreignKey2" class="Type2">
<column name="property2" />
<column name="property3" />
</many-to-one>
<many-to-one name="foreignKey3" class="Type2">
<column name="property2" />
<column name="property4" />
</many-to-one>
</class>


<class name="Type2" table="Type2" mutable="false" lazy="false">
<composite-id>
<key-property name="property2" column="property2" />
<key-property name="property3" column="property3" />
</composite-id>
<property name="property5" column="property5" />
</class>


<class name="Type3" table="Type3" mutable="false" lazy="false">
<composite-id>
<key-property name="property2" column="property2" />
<key-property name="property4" column="property3" />
</composite-id>
<property name="property6" column="property6" />
</class>

With the above mapping we get the org.hibernate.MappingException
Repeated column in mapping for entity: Type1 column: property2
(should be mapped with insert="false" update="false")

Looks like what we need is the ability to specify a <many-to-one> where we are able to specify the <insert>,<update> attributes
at a <column> level instead of at a <many-to-one> level : that way we can specify the repeated column to be insert=false,update=false
and use insert=true,update=true for the other column.

I realise the same topic has appeared a number of times in the forum : the gist of them seems to me to say that Hibernate does not support having the same column in multiple composite foriegn keys in the same table : is that so or if not what is the solution?

(I am sorry if the solution has already been specified in the forum but if so I seem to be missing it)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 15, 2005 6:34 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Use <formula>property2</formula>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 15, 2005 7:54 pm 
Newbie

Joined: Mon Aug 15, 2005 3:55 pm
Posts: 2
thanks that worked


Top
 Profile  
 
 Post subject: Overlapping keys, best practice?
PostPosted: Wed Mar 22, 2006 3:43 pm 
Newbie

Joined: Wed Mar 22, 2006 3:29 pm
Posts: 1
Gavin's short response suggests he's encountered this problem before, and that he has a baked answer for it. On the other hand, "formula" doesn't seem to have been designed to solve this problem (overlapping keys) -- and since the problem can't be solved with "column", that Hibernate was not designed to solve it.

So, since Hibernate was not designed to manage overlapping keys, can you comment on the potential consequences of using overlapping keys? Is it safe?

To be clear, by overlapping keys I am referring to the example of a column that is included in a composite natural primary key AND one or more composite natural foreign keys.


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