-->
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.  [ 1 post ] 
Author Message
 Post subject: confusion:Add additional attribute in many-to-many mapping
PostPosted: Mon Dec 28, 2009 4:47 am 
Newbie

Joined: Mon Dec 28, 2009 3:37 am
Posts: 1
Hello,

I am stuck in the following scenario

TABLES: Vehicle(vid, vdesc, basePrice, <Set>vFeatures),
Feature(fid, fcode, fprice),
VehicleFeatures(vid, fid, featurePrice)

Here I have associated Vechicle-Feature by many-to-many relationship. I am also storing the price of a particular feature for a particular vehicle in VehicleFeatures table. I would like to know is this correct way to map association between Vehicle and Feature or should I use One-Many relationship? If the association is correct how do I include it in mapping file of VehicleFeatures.hbm.xml. The problem is what should I use in the <id> tag of this mapping file. Below are the mapping files that I have created

Vehicle.hbm.xml
view plaincopy to clipboardprint?

1.
2. <?xml version="1.0" encoding="UTF-8"?>
3. <!DOCTYPE hibernate-mapping PUBLIC
4. "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
5. "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
6.
7. <hibernate-mapping>
8. <class name="com.dealership.vehicle.Vehicle" table="VEHICLE">
9. <id name="" column="vehicleId" type="long">
10. <generator class="sequence">
11. <param name="sequence">vehicle_seq</param>
12. </generator>
13. </id>
14.
15. <property name="vehicleDesc" column="VEHICLEDESCR"/>
16. <property name="basePrice"/>
17.
18. <many-to-one name="manufId"
19. class="com.dealership.vehicle.CarManufacturer"
20. column="manufId"/>
21.
22. <set name="vehicleFeatures" table="VEHICLE_FEATURES">
23. <key column="VEHICLEID"/>
24. <one-to-many class="com.dealership.vehicle.VehicleFeatures"/>
25. </set>
26. </class>
27. </hibernate-mapping>



Feature.hbm.xml
view plaincopy to clipboardprint?

1.
2. <?xml version="1.0" encoding="UTF-8"?>
3. <!DOCTYPE hibernate-mapping PUBLIC
4. "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
5. "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
6.
7. <hibernate-mapping>
8. <class name="com.dealership.vehicle.Feature" table="FEATURE">
9. <id name="id" column="FEATUREID" type="long">
10. <generator class="sequence">
11. <param name="sequence">feature_seq</param>
12. </generator>
13. </id>
14. <property name="featureCode" column="FEATURECODE"/>
15. <property name="featureDescription" column="FEATUREDECR"/>
16. </class>
17. </hibernate-mapping>



VehicleFeatures.hbm.xml (My problem is how do i write this file, what should be specified in the <ID> tag)
view plaincopy to clipboardprint?

1.
2. <?xml version="1.0" encoding="UTF-8"?>
3. <!DOCTYPE hibernate-mapping PUBLIC
4. "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
5. "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
6.
7. <hibernate-mapping>
8. <class name="com.dealership.vehicle.VehicleFeatures" table="VEHICLE_FEATURES">
9. <id>?????
10. <property name="featureValue" column="FEATUREVALUE" />
11. <many-to-one name="vehicle"
12. class="com.dealership.vehicle.Vehicle"
13. column="VEHICLEID"/>
14. <many-to-one name="feature"
15. class="com.dealership.vehicle.Feature"
16. column="FEATUREID"/>
17. </class>
18. </hibernate-mapping>



Since I need an explicit mapping for VehicleFeatures, so haven't used many-to-many between Vehicle and Feature.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.