Composite exception


#1

Hello,

I’ve been tasked with correcting some legacy code (Hibernate 5.2.17), but it’s solution has so far escaped me. The hibernate.config.xml references the following SidOrgRl.hbm.xml:

<?xml version="1.0"?>
 <class name="mil.dfas.tso.sid.domain.SidOrgRl" table="SID_ORG_RL" schema="SID_OWN"
        dynamic-insert="true" dynamic-update="true" lazy="true">
     <composite-id mapped="true">
         <key-property name="orgDfasAsgndId" type="long">
             <column name="ORG_DFAS_ASGND_ID" precision="10" scale="0" />
         </key-property>
         <key-property name="rlTyCd" type="string">
             <column name="RL_TY_CD" length="2" />
         </key-property>
     </composite-id>
     <many-to-one name="sidOrg" class="mil.dfas.tso.sid.domain.SidOrg" update="false" insert="false" fetch="select">
         <column name="ORG_DFAS_ASGND_ID" precision="10" scale="0" not-null="true" />
     </many-to-one>
 </class>

If I run as is I get:

-org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘sessionFactory’ defined in ServletContext resource [/WEB-INF/hibernate-config.xml]: Invocation of init method failed; nested exception is org.hibernate.boot.MappingException: mapped composite identifier must name component class to use. : origin(C:\Users…persistence\hibernate\mapping\SidOrgRl.hbm.xml)

or if I add class=“SidOrg” to <composite-id class=“SidOrg”… I get:

-org.springframework.beans.factory.BeanCreationException:…hibernate.boot.MappingException: Association [mil.dfas.tso.sid.domain.SidOrg.sidInfoAstOrgs] references an unmapped entity [mil.dfas.tso.sid.domain.SidOrg.sidInfoAstOrgs] : origin(C:\Users…persistence\hibernate\mapping\SidOrg.hbm.xml)

While I get the gist of the problem in that Hibernate’s not seeing a proper mapping I haven’t found anything online specifically addressing this particular composite key issue. Is it a syntax problem on my end? A 5.2.17 bug? etc.

Thanks for any insight,
Dave


#2

Try adding the class attribute to the composite-id.

Hbm mappings are considered deprecated since JPA 1.0 has emerged (2006). If you are migrating to 5.x, it’s time to migrate to annotations or ORM.xml mappings too. They are much better supported too.


#3

Thank you very much. Much of the code I’m finding dates back to 2005-06, so that would make sense. I really appreciate your help.

-All the best,
Dave


#4

You’re welcome. Here’s an article for an example of how you can map composite identifers with JPA annotations.