-->
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.  [ 5 posts ] 
Author Message
 Post subject: "property-ref" for "key-many-to-one" tag
PostPosted: Wed May 17, 2006 6:21 am 
Newbie

Joined: Thu May 04, 2006 3:44 am
Posts: 2
Hi,
I am working with a database which structure I cannot change. The database scheme is a little bit "strange":
I've got 2 tables with a one-to-many connection. Both tables have composite-ids. However, just a part of the composite-id of the parent-table is part of the composite-id of the child-table. The rest of the key is not referenced at all.

Code:
=table A=       =table B=
_pk1     <--    _pk1
_pk2            _pk3
more_attr       more_attr


I do not have to care about inconsistences, because _pk3 is just a primary key for history-reasons. Is it possible to model this in hibernate? I am looking for something like "property-ref" for the key-many-to-one tag which of course make no sense in general but in my case.

Thanks a lot for your help!
Greeting, Heiko


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 17, 2006 7:23 am 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
If pk_3 is not in use, you might simply ignore it and treat it as normal property.

Best Regards

Sebastian

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 17, 2006 8:27 am 
Newbie

Joined: Thu May 04, 2006 3:44 am
Posts: 2
What do you mean with ignore? I do have to map it in class A, right? This is my mapping, which results (of course) in the following error:

Code:
Initial SessionFactory creation failed.org.hibernate.MappingException: Foreign key (...) must have same number of columns as the referenced primary key (...)


Code:
<hibernate-mapping>
    <class name="A" table="a">
        <composite-id name="id" class="AId">
            <key-many-to-one name="pk1" column="pk_1" />
            <key-property name="pk2" type="timestamp">
                <column name="pk_2" length="26" />
            </key-property>
        </composite-id>
...
    </class>
</hibernate-mapping>


<hibernate-mapping>
    <class name="B" table="b">
        <composite-id name="id" class="BId">
            <key-property name="pk1" type="int">
                <column name="pk_1" />
            </key-property>
            <key-property name="pk3" type="timestamp">
                <column name="pk_3" length="26" />
            </key-property>
        </composite-id>
...
    </class>
</hibernate-mapping>



Top
 Profile  
 
 Post subject:
PostPosted: Wed May 17, 2006 9:33 am 
Expert
Expert

Joined: Tue Apr 25, 2006 12:04 pm
Posts: 260
check these mappings

Code:
<hibernate-mapping>
    <class name="A" table="a">
        <composite-id name="id" class="AId">
            <key-property name="pk1" column="pk_1" />
            <key-property name="pk2" type="timestamp">
                <column name="pk_2" length="26" />
            </key-property>
        </composite-id>

   <many-to-one name="classBObject" column="pk_1" class="B" insert="false" update="false"/>
...
    </class>
</hibernate-mapping>


<hibernate-mapping>
    <class name="B" table="b">
        <composite-id name="id" class="BId">
            <key-property name="pk1" type="int">
                <column name="pk_1" />
            </key-property>
            <key-property name="pk3" type="timestamp">
                <column name="pk_3" length="26" />
            </key-property>
        </composite-id>
...
    </class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 17, 2006 5:04 pm 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
ignore means do not use it as key property but simply as a property. You must of course do this on both sides.

Best Regards

Sebastian

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


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