-->
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: Discriminator not used in foreign keys
PostPosted: Thu May 26, 2005 8:28 am 
Newbie

Joined: Thu May 26, 2005 6:00 am
Posts: 3
Hi, I m trying to use Inheritance , table per hierarchie, I have a first table A
with a composite primary key ( type, id ), id is generated by a sequence
for each value of type ( don't have unique constraint on id but on both type and id ).

I have a second table B which has a foreign key to A.id and no column
for A.type because the value is constant ( all entities of B refers to
A entity for which A.type = 1 )

When I try to map the Many-to-One association, hibernate reject the code
because the foreign key has not the same number of column than the primary key.
I would consider that the discriminator column would be used for the join, but not.

Does someone have an idea on this ?


Hibernate version:3.0.4

Mapping documents:
<class name="A" table="A">
<composite-id name="dicoPk" class="APk">
<key-property name="type" column="type" type="int" />
<key-property name="id" column="id" type="long" />
type="int" />
</composite-id>

<discriminator column="type" type="int" ></discriminator>
<subclass name="SubA" discriminator-value="1" ></subclass>
</class>
<class name="B" table="B" >
<id name="id" column="b_id" type="long" />
<many-to-one name="subA" column="a_id" />
</class>



Full stack trace of any exception that occurs:org.hibernate.MappingException: Foreign key (FK5CA40550C951E49D:B[a_id])) must have same number of columns as the referenced primary key (A[type, id])
at org.hibernate.mapping.ForeignKey.alignColumns(ForeignKey.java:86)
at org.hibernate.mapping.ForeignKey.setReferencedTable(ForeignKey.java:51)
at org.hibernate.cfg.Configuration.secondPassCompileForeignKeys(Configuration.java:953)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:898)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1049)
at com.nnr.tests.Test.setUp(Test.java:33)
at com.intellij.rt.execution.junit2.JUnitStarter.main(JUnitStarter.java:31)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:78)


Name and version of the database you are using:postgresql 8.0


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 26, 2005 10:55 am 
Senior
Senior

Joined: Sun Mar 14, 2004 10:16 am
Posts: 129
Location: Ankara
Let the id to be only "id" not (id, type). It is meaningless to give such a composite id.

_________________
-developer


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 26, 2005 11:08 am 
Newbie

Joined: Thu May 26, 2005 6:00 am
Posts: 3
I have simplify the example, I can't remove the type from the primary key, I can't modify the structure of the database.

Using a formula tag as child of many-to-one tag helps but I can't be done using Annotations and I feel this ugly.

Thanks for your answer, have any other idea ?


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.