• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate: confusion how to include seperate attribute in many-to-many mapping file

 
Maya Dolas
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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


Feature.hbm.xml


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


Since I need an explicit mapping for VehicleFeatures, so haven't used many-to-many between Vehicle and Feature.
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since the central table has a field in it, the central table, which we usually think of as a join table, isn't really a true join table in the pure sense of the word.

One approach that works is to divide the many to many into two one to many relationships pointing to the join table.

-Cameron McKenzie
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic