-->
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.  [ 1 post ] 
Author Message
 Post subject: one-to-many map referencing alternate key with propery-ref
PostPosted: Tue Jan 31, 2012 4:59 am 
Newbie

Joined: Thu Aug 25, 2011 4:52 am
Posts: 5
Hi,

I have to map a legacy database and tried to define a bi-directional <one-to-many> relationship between two classes, where the foreign-key relationship is not established with the primary key, but with an alternate column/property with an unique constraint. Here the mapping:

Code:
<class name="BasisPickListe" table="PICKLISTEN">
    <composite-id>
        <key-property name="nummer" column="NR_PICKL" type="string"/>
        <key-many-to-one name="lager" lazy="false">
            <column name="LAGER"/>
        </key-many-to-one>
    </composite-id>
    <discriminator type="string" formula="...">
    <property name="sendungsnummer" column="SEND_NR" type="string"/>       
</class>

<subclass name="PickListe" extends="BasisPickListe" discriminator-value="PickListe">
    <property name="empfaengerId" column="ID_EMPFAENGER" type="string"/>
    <many-to-one name="sammelPickListe"
                        class="SammelPickListe"
                        column="ID_EMPFAENGER"
                        property-ref="sendungsnummer"
                        not-null="false"
                        not-found="ignore"/>
</subclass>

<subclass name="SammelPickListe" extends="BasisPickListe" discriminator-value="SammelPickListe">
    <map name="mSammelPickListen" inverse="true">
        <key property-ref="empfaengerId" column="SEND_NR" />
        <map-key formula="NR_PICKL" type="string"/>
        <one-to-many class="PickListe"/>
    </map>       
</subclass>   


The problem ist the <map> definition in the subclass "SammelPickListe". I get the error "org.hibernate.MappingException: property [empfaengerId] not found on entity [com.rhenus.rml.database.lvs.helas.tables.SammelPickListe]" with this mapping definition.

I tried to define the mapping according to the sample "Associations on alternate keys" (http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/example-mappings.html#example-mappings-association-alternatekeys).

Hibernate seems to look for the property "empfaengerId" in the subclass "SammelPickListe". But "empfaengerId" is the foreign key property in the class "PickListe". The join should be made by the clause SammelPickListe.SEND_NR = PickListe.empfaengerId.

Currently I select the content of the map with the following Java code (as workaround):
Code:
Criterion restriction = Restrictions.eq("empfaengerId", sammelPickListe.getSendungsnummer());
Criteria  selectPickLists = session.createCriteria(BasisPickListe.class).add(restriction);
List<BasisPickListe> pickLists = selectPickLists.list();


I wonder how this can be done in the mapping definition.

Thomas


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.