-->
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.  [ 6 posts ] 
Author Message
 Post subject: New to hibernate .Need Help in Mapping
PostPosted: Tue Feb 24, 2009 7:11 am 
Newbie

Joined: Tue Feb 24, 2009 6:52 am
Posts: 15
Hello
I m uisng Hibernate 3.2.5 and i m new to hibernate technology
I want to know how to map Primary key and foreign key in my .xml file
Following is the table structure

Products
pid----> PK (has been referred as FK in 3 tables)
name
etc

Discounts
did---> PK
pid---> FK from products table

How do write XML for mapping these two tables

this is the code in Discount.hbm.xml
<hibernate-mapping>
<class name="discounts" table="discounts_tbl">
<id name="did" type="int" column="did" >
<generator class="assigned"/>
</id>

<id name="productId" type="int" column="productId" >
<generator class="foreign"/>
</id>
<many-to-one name="prd" class="products" column="productId"/>


<property name="quantityFrom">
<column name="quantityFrom"/>
</property>
<property name="quantityTo">
<column name="quantityTo"/>

.....
....
.....

etc

Please HELP.
Regards Vikram


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 24, 2009 7:30 am 
Expert
Expert

Joined: Fri Jan 30, 2009 1:47 am
Posts: 292
Location: Bangalore, India
Your mapping seems to be quite OK. Try with this mapping and let us know if you have any issues.

_________________
Regards,
Litty Preeth


Top
 Profile  
 
 Post subject: What mapping
PostPosted: Tue Feb 24, 2009 7:33 am 
Newbie

Joined: Tue Feb 24, 2009 6:52 am
Posts: 15
?????


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 24, 2009 7:37 am 
Expert
Expert

Joined: Fri Jan 30, 2009 1:47 am
Posts: 292
Location: Bangalore, India
From the Discount.hbm.xml u specified remove the
<id name="productId" type="int" column="productId" >
<generator class="foreign"/>
</id>

Then your mapping is fine.

_________________
Regards,
Litty Preeth


Top
 Profile  
 
 Post subject: thanx
PostPosted: Tue Feb 24, 2009 7:43 am 
Newbie

Joined: Tue Feb 24, 2009 6:52 am
Posts: 15
littypreethkr wrote:
From the Discount.hbm.xml u specified remove the
<id name="productId" type="int" column="productId" >
<generator class="foreign"/>
</id>

Then your mapping is fine.


Thank you


It worked fine
Do i need to make any changes in products.hbm.xml
this is the code for products.xml

<hibernate-mapping>
<class name="products" table="products_tbl">
<id name="productId" type="int" column="productId" >
<generator class="assigned"/>
</id>
<property name="productShortName">
<column name="productShortName" />
</property>
<property name="productDescription">
<column name="productDescription"/>
</property>
<property name="unitOfMeasurement">
<column name="unitO....

..
..

I have one more problem .If you can spare 5 mins for me...it would be really great.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 24, 2009 7:48 am 
Expert
Expert

Joined: Fri Jan 30, 2009 1:47 am
Posts: 292
Location: Bangalore, India
products mapping also seems fine.

_________________
Regards,
Litty Preeth


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