-->
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: Reuse a class for many tables
PostPosted: Tue Jun 27, 2006 3:00 pm 
Newbie

Joined: Tue Jun 27, 2006 2:51 pm
Posts: 14
Hi Guys,


I'm trying to map a class called Color that contains a Set property of Color objects called
interiorColors. I have this data in two separate tables that are related to each other with a many-to-many
relationship, so there's a join table in there as well. I know how to handle this situation if the class type
of the property is that of another class, but in this case I want the interiorColor's to be of the same type \
as the Color object. I'm not sure how to go about this. If in the many-to-many element I specify the Color class
in the class attribute, it maps it to the original Color table, not the interiorColor table. How do I reuse the
Color class to map to a different table?

Thanks.

- Mike



I'm running with Hibernate 3.0
Mapping documents:
<set name="interiorColors" table="mmsaBPTrimColorInt">
<cache usage="read-only" region="standardCache"/>
<key column="ExtColorId"/>
<many-to-many column="IntColorId" class="com.organic.mitsu.hib.Color">
</many-to-many>
</set>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 27, 2006 4:50 pm 
Expert
Expert

Joined: Tue Apr 25, 2006 12:04 pm
Posts: 260
If you want to map a class for more than one table see this http://www.hibernate.org/hib_docs/v3/re ... entityname


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 27, 2006 5:19 pm 
Newbie

Joined: Tue Jun 27, 2006 2:51 pm
Posts: 14
Thanks for the info. I found this link shortly after posting. Sorry I should have researched this more. I'll post what I've mapped out, should anyone else need the same solution:

Code:

<hibernate-mapping package="com.organic.mitsu.hib">

   <!-- this maps Color to the exterior color table -->
   <class name="Color" table="mmsaBPTrimColorExtContent">
   
      <cache usage="read-write" region="standardCache"/>
      
      <id name="colorId" column="ExtColorId" type="integer">
         <generator class="native"/>
      </id>
      
      <property name="colorName" column="ExtColorName" type="string"/>
      
      <!-- define a set of color objects under the interiorColors property
         notice the use of the entity-name reference  -->
      <set name="interiorColors" table="mmsaBPTrimColorInt">
         <cache usage="read-only" region="standardCache"/>
         <key column="ExtColorId"/>
         <many-to-many class="Color" column="IntColorId" entity-name="interior"/>
      </set>
      
   </class>
   
   <!-- define a new map to Color for the interior color table, specify a value
      for the entity-name attribute to distinguish this separate mapping
    -->
   <class name="Color" table="mmsaBPTrimColorIntContent" entity-name="interior">
      
      <cache usage="read-write" region="standardCache"/>
      
      <id name="colorId" column="IntColorId" type="integer">
         <generator class="native"/>
      </id>
      
      <property name="colorName" column="IntColorName" type="string"/>
      
   </class>
   
</hibernate-mapping>



Thanks again for the help.


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.