-->
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: How to map several tables to one class
PostPosted: Sun Jul 01, 2007 11:07 pm 
Regular
Regular

Joined: Tue Jun 26, 2007 11:50 am
Posts: 105
Hello,

Hello, I would like to know if it is possible to map several tables to one class ?
Here is a description of my problem : I have a class Product which contains a list of Quantities (a property of type Weight, which is a class I have defined). Those quantities are stored in a separate table and I would like to map each of them to the class Weight. Moreover, Product has a property called UnitWeight which is of type Weight and which data are sored in the Product table. I would also like to map this field "UnitWeight" to the Weight class. Is it possible ?


Hier is my map file :

<class name="Product" lazy="false">
<id name="Id">
<generator class="identity" />
</id>
<bag name="MinQuantity" table="MinQuantity" lazy="false" order-by="MinQuantity">
<key column="Product_Id" />
<one-to-many class="Quantity" />
</bag>
<one-to-one name="UnitWeight" class="Weight" />
</class>

<class name="Quantity" table="MinQuantity" lazy="false">
<id name="Id">
<generator class="identity" />
</id>
<discriminator column="Unit" type="String" />
<subclass name="Weight" discriminator-value="kg">
<property name="Value" column="MinQuantity" />
</subclass>
<subclass name="NumberOfPiece" discriminator-value="p.">
<property name="Value" column="MinQuantity" />
</subclass>
</class>

<class name="Weight" table="Product">
<id name="Id">
<generator class="identity" />
</id>
<property name="Value" column="UnitWeight" />
</class>

For the moment, this doesn't work. I get an error :
Duplicate class/entity mapping Weight

Do you have an idea to solve this problem ?

thanks.
[/b]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 02, 2007 11:11 am 
Expert
Expert

Joined: Fri May 13, 2005 11:13 am
Posts: 292
Location: Rochester, NY
There is a <join> element in the current trunk. That would require downloading a building the source.

More likely, for such a lightweight object as 'Weight' you should not use a separate table, but instead map it as a <component> (see [url]
http://www.hibernate.org/hib_docs/nhibe ... nents.html[/url]).


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 02, 2007 12:31 pm 
Regular
Regular

Joined: Tue Jun 26, 2007 11:50 am
Posts: 105
Thank you very much. :-)
Using a <component> is perfect for my case.

Quote:
There is a <join> element in the current trunk. That would require downloading a building the source.

For more complex classes it could be interessant. I would like to have a look at this. Where could I find this building source ?


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.