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
|