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.
|