-->
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.  [ 3 posts ] 
Author Message
 Post subject: More help with mappings
PostPosted: Wed Sep 15, 2004 8:02 am 
Beginner
Beginner

Joined: Thu Sep 02, 2004 9:17 am
Posts: 21
Hi there, can someone please help me with a mapping?

I have these tables and columns
PRICE
ID integer
AMOUNT double
REMARK varchar

REBUILDING
ID integer
PRICE_ID integer (links to PRICE)
CONSTRUCTION_ID integer (links to CONSTRUCTION)
DATE date

CONSTRUCTION
ID integer
NAME string

Which I want to map to these objects:
Price{
Long id;
Double amount;
String remark;
}

Rebuilding{
Long id;
Price price;
Date date;
}

Construction{
Long id;
String name;
Collection rebuildings; // collection of Rebuilding objects
}


But, when I try to "load" a Construction, I do not get the corresponding collection of Rebuilding objects.

Obviously there is something wrong with my mappings...


Hibernate version:
2.1.6

Mapping
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">


<hibernate-mapping>

<class name="dk.pk.Price" table="PRICE" >
<id name="id" type="long" column="ID">
<generator class="increment"/>
</id>
<property name="amount" column="AMOUNT" type="double" />
<property name="remark" column="REMARK" type="string" />
</class>


<class name="dk.pk.Rebuilding" table="REBUILDING" >
<id name="id" type="long" column="ID">
<generator class="increment"/>
</id>
<many-to-one name="price" column="PRICE" class="dk.pk.Price" cascade="save-update" />
<property name="date" column="DATE" type="date" />
</class>


<class name="dk.pk.Construction" table="CONSTRUCTION" >
<id name="id" type="long" column="ID">
<generator class="increment"/>
</id>
<property name="name" column="NAME" type="string" />
<set name="rebuildings" table="REBUILDING">
<key column="ID"/>
<composite-element class="dk.pk.Rebuilding">
</composite-element>
</set>
</class>

</hibernate-mapping>

Thanks for any advice,
Peter


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 15, 2004 8:19 am 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
Try
Code:
         <key column="CONSTRUCTION_ID"/>
         <one-to-many class="dk.pk.Rebuilding"/>

instead of
Code:
         <key column="ID"/>
         <composite-element class="dk.pk.Rebuilding"/>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 15, 2004 9:07 am 
Beginner
Beginner

Joined: Thu Sep 02, 2004 9:17 am
Posts: 21
Thanks very much!
Works a treat now.


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