I am having trouble figuring out how to accomplish the following JOIN:
I have three tables, Device, DeviceFeature and Feature.
Device represents a physical hardware device. Feature contains features that a device may have. DeviceFeature contains the values for these features for each Device.
Example:
Code:
Device
===========
DeviceId (PK)
Name
Feature
===========
FeatureId (PK)
Name
DeviceFeature
===========
DeviceFeatureId (PK)
DeviceId (FK)
FeatureId (FK)
Value
So, an example device would be:
Code:
DeviceId Name
======== ==========
1 Server
and an example feature would be:
Code:
FeatureId Name
========= ==========
1 IPAddress
so, if I wanted to assign an IP address to device 1 (Server) I would have the following DeviceFeature record
Code:
DeviceFeatureId DeviceId FeatureId Value
=============== ======== ========= ========
1 1 1 192.168.0.1
The problem I am having is coming up with an efficient mapping in Hiberate. Ideally I want a Device to have a map of Features, with the key being Feature.Name and the value being DeviceFeature.Value (and have this map cascade to inserts, updates and deletes).
So far I have a Device mapping to a set of DeviceFeatures and each DeviceFeature maps to a Feature (this is a long painful traversal)
Any help you can provide would be appreciated.
Thanks,
Mark