-->
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.  [ 6 posts ] 
Author Message
 Post subject: Hibernate Upgrade - alternate key not functional
PostPosted: Mon Nov 28, 2016 9:07 am 
Newbie

Joined: Mon Nov 28, 2016 7:37 am
Posts: 3
I'm upgrading a large system from Spring 2.5 to 4.3. We use also a quiete old Hibernate version 3.2.6.ga. After many problems with an upgrade to Hibernate 4, i've decided to stay at the latest Hibernate 3 version.

But.. there are constructs which are not functional anymore. We use composite foreign keys, which are referencing nonprimary keys. (s. http://learningviacode.blogspot.nl/2012 ... ncing.html)

Thats my construct
Code:
<class name="ApLocation" table="AP_LOCATION"
    lazy="true" dynamic-update="true" optimistic-lock="dirty">
    <meta attribute="extends">EntityObjectWithIdTs</meta>
    <meta attribute="implements">EntityWithMandator</meta>
    <id name="id" type="java.lang.Long" column="ID_LOCATION" length="22">
        <generator class="IdGeneratorTable" />
    </id>

    <discriminator
        formula="case when PERSON_INSTITUTION = 'IP' then 'C' else 'A' end" />

....
    <property name="bpId" column="ID_JURISTIC_PERSON" type="java.lang.Long"
        insert="false" update="false" />
    <property name="addrId" column="ID_ADDRESS" type="java.lang.Long"
        insert="false" update="false" />

    <properties name="comp_BpAddr" insert="false" update="false" unique="false">
        <property name="bpId" column="ID_JURISTIC_PERSON" type="java.lang.Long"
            insert="false" update="false" />
        <property name="addrId" column="ID_ADDRESS" type="java.lang.Long"
            insert="false" update="false" />
    </properties>
....

<subclass name="ApAddressLocation"
    extends="ApLocation"
    discriminator-value="A" dynamic-update="true">

    <set name="apContactPersonLocations" lazy="true"
        where="PERSON_INSTITUTION = 'IP'" inverse="true" >

        <key property-ref="comp_BpAddr" unique="false" >
            <column name="ID_JURISTIC_PERSON"/>
            <column name="ID_ADDRESS" />
        </key>
        <one-to-many class="ApContactPersonLocation"/>
    </set>
</subclass>


<subclass name="de.klopotek.mex.bus.ap.entity.ApAddressLocation"
    extends="de.klopotek.mex.bus.ap.entity.ApLocation"
    discriminator-value="A" dynamic-update="true">

    <set name="apContactPersonLocations" lazy="true"
        where="PERSON_INSTITUTION = 'IP'" inverse="true" >

        <key property-ref="comp_BpAddr" unique="false" >
          <formula>ID_JURISTIC_PERSON</formula>
          <formula>ID_ADDRESS</formula>
        </key>

        <one-to-many class="ApContactPersonLocation"/>
    </set>

</subclass>


At startup the following exception is thrown

Code:
Caused by: org.hibernate.MappingException: property [comp_BpAddr] not found on entity [ApAddressLocation]
at org.hibernate.mapping.PersistentClass.getRecursiveProperty(PersistentClass.java:379)
at org.hibernate.cfg.HbmBinder.bindCollectionSecondPass(HbmBinder.java:2533)
at org.hibernate.cfg.HbmBinder$CollectionSecondPass.secondPass(HbmBinder.java:2782)
at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:65)
at org.hibernate.cfg.Configuration.originalSecondPassCompile(Configuration.java:1716)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1423)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1375)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:660)
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:191)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
... 52 more


Any ideas how i can solve this problem?


Top
 Profile  
 
 Post subject: Re: Hibernate Upgrade - alternate key not functional
PostPosted: Mon Nov 28, 2016 10:19 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1638
Location: Romania
You might want to migrate the mappings from HBM to Annotations wince they are better supported in later versions on Hibernate (4.x or 5.x).

_________________
If you liked my answer, you are going to love my High-Performance Java Persistence book and my blog as well.


Top
 Profile  
 
 Post subject: Re: Hibernate Upgrade - alternate key not functional
PostPosted: Mon Nov 28, 2016 10:34 am 
Newbie

Joined: Mon Nov 28, 2016 7:37 am
Posts: 3
we have nearly 900 mapping files, sometimes really complex and together with named queries - so migration is not really an option. Also going to Hibernate 4/5 is not a short term option, cause we use Hibernate together with Spring and have extended Hibernate and Spring classes, which can't easily migrated.
But the question is - why is that feature killed, or is this a bug, which is not fixed, cause no one filled in an issue?


Top
 Profile  
 
 Post subject: Re: Hibernate Upgrade - alternate key not functional
PostPosted: Mon Nov 28, 2016 1:54 pm 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1638
Location: Romania
The legacy HBM is rather deprecated since Hibernate has become a JPA provider (10 years ago). If you plan on migrating to Spring 4 or 5, then you should migrate Hibernate to 5 as well.

You can semi-automate the HBM-> Annotation migration process like this:

1. You use HBM2DDL on a temp database to generate a mirror DB schema from HBM mappings
2. You use Reverse Engineering from the temp database to generate Annotations

Hibernate 6 will come with an extension to JPA XML mappings, and we'll probably deprecate the HBM configurations for good. That's why I advise you to do this migration.

_________________
If you liked my answer, you are going to love my High-Performance Java Persistence book and my blog as well.


Top
 Profile  
 
 Post subject: Re: Hibernate Upgrade - alternate key not functional
PostPosted: Tue Nov 29, 2016 3:28 am 
Newbie

Joined: Mon Nov 28, 2016 7:37 am
Posts: 3
is it possible to mix XML and annotation based mapping as it described here ?
http://www.technology-ebay.de/the-teams/mobile-de/blog/mixing-annotation-based-and-xml-mapping-in-hibernate.html


Top
 Profile  
 
 Post subject: Re: Hibernate Upgrade - alternate key not functional
PostPosted: Tue Nov 29, 2016 3:49 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1638
Location: Romania
Sure you can. You can do the migration gradually. In fact, you can even overrule Annotations wth XML, or the other way around. Take a look on hibernate.mapping.precedence.

_________________
If you liked my answer, you are going to love my High-Performance Java Persistence book and my blog as well.


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