-->
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: Mapping one-to-many with Map
PostPosted: Mon Oct 03, 2005 2:00 pm 
Newbie

Joined: Mon Oct 03, 2005 1:42 pm
Posts: 2
Hibernate version:
2.0

Full stack trace of any exception that occurs:
org.hibernate.MappingException: Error reading resource: fr/jet/contacteur/client/stats/dao/hibernate/CampagneStats.hbm.xml

Name and version of the database you are using:
mysql 4.1


I want to map my table CampagneStats to my composite-key table CampagneStatsCumulTime by a Map, using "time_limit" which is part of the primary key as my map-key.

My mapping of CampagneStatsCumulTime :
...
<class name="CampagneStatsCumulTime" table="campagne_stats_cTime">
<composite-id >
<key-many-to-one name="campagne" class="CampagneStats" column="ref_campagne" />
<key-property name="nLimit" type="string" column="time_limit"/>
</composite-id>
...

And CampagneStats
<class name="CampagneStats" table="campagne_stats">
<id name="reference" column="ref_campagne">
<generator class="foreign">
<param name="property">campagne</param>
</generator>
</id>
<map name="CumulTimes" inverse="true" cascade="all-delete-orphan">
<key>
<column name="ref_campagne" not-null="true"/>
<column name="time_limit"/>
</key>
<one-to-many class="CampagneStatsCumulTime"/>
</map>


What is wrong here? I also tried :
<map name="CumulTimes" inverse="true" cascade="all-delete-orphan">
<key>
<column name="ref_campagne" not-null="true"/>
</key>
<map-key column="time_limit"/>
<one-to-many class="CampagneStatsCumulTime"/>
</map>

with no more luck. However if i use Set instead of map in the first example it works fine.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 03, 2005 5:32 pm 
Regular
Regular

Joined: Fri Sep 09, 2005 11:35 am
Posts: 101
u did not provide the stacktrace.
though i believe that for a map you will need a "key" and "element" pair in the mapping.
Your stacktrace should mention this.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 04, 2005 4:55 am 
Newbie

Joined: Mon Oct 03, 2005 1:42 pm
Posts: 2
Solved it

No I did not provide the stack-trace because I did not have it. Once I had activated it properly I could see what was wrong (missing type="integer" in the map-key flag). Thank you.

Working mapping :
<map name="CumulTimes" inverse="true" cascade="all-delete-orphan">
<key column="ref_campagne" not-null="true"/>
<map-key column="time_limit" type="integer" />
<one-to-many class="CampagneStatsCumulTime"/>
</map>

Johan


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.