We are trying to migrate a project from hibernate 3 to hibernate 5. We have a legacy database that contains composite foreign key referencing non primary keys. To best explain the problem, I take the example from
http://learningviacode.blogspot.com/201 ... ncing.htmlHere is the mapping file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.ec.composite_foreign_non_primary">
<class name="Student" table="STUDENT">
<id name="id" type="integer" column="ID">
<generator class="native" />
</id>
<properties name="StudentKey" unique="true">
<property name="name" column="STUDENT_NAME" />
<property name="schoolName" column="SCHOOL_NAME" />
</properties>
<set name="vehicles" cascade="all" inverse="true">
<key property-ref="StudentKey" >
<column name="STUDENT_NAME"/>
<column name="SCHOOL_NAME"/>
</key>
<one-to-many class="Vehicle" />
</set>
</class>
</hibernate-mapping>
It works with Hibernate 3.3. With hibernate 5, it complains StudentKey not found.
Stack Trace:
Caused by: org.hibernate.MappingException: property [StudentKey] not found on entity [com.ec.composite_foreign_non_primary.Student]
at org.hibernate.mapping.PersistentClass.getRecursiveProperty(PersistentClass.java:425)
at org.hibernate.boot.model.source.internal.hbm.ModelBinder$AbstractPluralAttributeSecondPass.bindCollectionKey(ModelBinder.java:3266)
at org.hibernate.boot.model.source.internal.hbm.ModelBinder$AbstractPluralAttributeSecondPass.doSecondPass(ModelBinder.java:3086)
at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1621)
at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1589)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:278)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:83)
at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:418)
at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:87)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:692)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:724)
Does Hibernate 5 support at all this kind of mapping for legacy database? Your insight will be appreciated.