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: Mapping problem with 3 tables (product >price > priceg
PostPosted: Wed Feb 06, 2008 8:27 am 
Beginner
Beginner

Joined: Mon Jan 14, 2008 10:58 am
Posts: 24
I know it's simple for you guys but I can't make it work!
I have three tables in the database: Products, ProductsPriceGroups and PriceGroups.

One product can have different prices depending on which pricegroup the customer is in.
Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
   <class name="Swh.Entities.Product, Swh.Entities" table="Products">
      <id name="Id" column="ProductId" type="int" unsaved-value="0">
         <generator class="identity" />
      </id>
      <property name="Name" column="ProductName" type="String"/>
      <bag name="Prices" table="ProductsPriceGroups" lazy="true">
         <key column="ProductId"/>
         <property name="Price" column="Price" type="double"/>
         <many-to-one column="PriceGroupId" class="Swh.Entities.PriceGroup, Swh.Entities" />
      </bag>
</hibernate-mapping>


Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
   <class name="Swh.Entities.Pricegroup, Swh.Entities" table="PriceGroups">
      <id name="Id" column="PriceGroupId" type="int" unsaved-value="0">
         <generator class="identity" />
      </id>
      <property name="Name" column="PriceGroupName" type="String"/>
   </class>
</hibernate-mapping>


The problem with this code is that bag doesn't allow a property.
So, how should the mapping look like?

(I have looked at the product/order/orderline example but I can't translate it to my problem!)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 06, 2008 12:01 pm 
Hibernate Team
Hibernate Team

Joined: Tue Jun 13, 2006 11:29 pm
Posts: 315
Location: Calgary, Alberta, Canada
You need to wrap the properties in <composite-element> as illustrated in the docs here:
http://www.hibernate.org/hib_docs/nhibe ... ollections

_________________
Karl Chu


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.