-->
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.  [ 2 posts ] 
Author Message
 Post subject: Forced to use set instead of map
PostPosted: Mon Jan 23, 2006 11:44 am 
Newbie

Joined: Tue Jan 17, 2006 5:22 pm
Posts: 3
Converting an existing non-hibernate app to Hibernate. (3.0)

I need to re-use a column for both the index and as a property in a composite element (see the ObjName column/property in this example):

Mapping documents:

Code:
<hibernate-mapping default-lazy="false">
   <class name="MyClass" table="MYCLASSTABLE">
      <id name="id" column="ID">
         <generator class="native"/>
      </id>
      <property ..../>
      <map name="MySubObj" table="SUBOBJ">
         <key column="MYCLASSID"/>
         <index column="OBJNAME" type="string"/>
         <composite-element class="MySubObj">
            <property name="ObjName" column="OBJNAME"/>
            <property ..../>
            <property ..../>
            <property ..../>
         </composite-element>
      </map>
   </class>
</hibernate-mapping>


Hibernate gives an exception when processing the mapping docs:

Code:
org.hibernate.MappingException: Repeated column in mapping for collection: MyClass.MySubObj column: OBJNAME
   at org.hibernate.mapping.Collection.checkColumnDuplication(Collection.java:290)
   at org.hibernate.mapping.Collection.checkColumnDuplication(Collection.java:313)
   at org.hibernate.mapping.Collection.validate(Collection.java:270)
   at org.hibernate.mapping.IndexedCollection.validate(IndexedCollection.java:67)
   at org.hibernate.cfg.Configuration.validate(Configuration.java:987)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1147)
   at <my app>



So as a work-around, I change the map to a set and have taken out the <index column="OBJNAME".../> line from the mapping file.

Is there anyway to keep this as a map? In my workaround, I'm converting to/from a map in the [get/set]MySubObj( Set set) getter/setter pair.
This works kinda okay, but I'm getting a lot of re-writing of the set in the SUBOBJ db table that I'm assuming is caused by me not preserving Hibernate's original set.

-Trevor


Top
 Profile  
 
 Post subject: in 3.1.1 works with formula
PostPosted: Tue Jan 24, 2006 12:26 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
The following mapping allows you to do what you want (at least in 3.1.1):

<class table="map_holders" name="mapmap.MapHolder" lazy="false">
<id name="id">
<generator class="assigned"/>
</id>

<map name="elements" table="map_elements" >
<key column="mh_id"/>
<map-key type="java.lang.String" formula="name"/>
<composite-element class="mapmap.MapElement">
<property name="name" column="name"/>
<property name="label" column="label"/>
</composite-element>
</map>

</class>

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


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