Hi all
I'm new in Hibernate programming and I've a problem defining a N:M relationship with attributes.
For example, suppose to have the following data model:
CREATE TABLE Concept (
id CHARACTER VARYING(20) NOT NULL,
description TEXT,
...
PRIMARY KEY(id)
);
CREATE TABLE Feature (
id BIGINT NOT NULL,
name CHARACTER VARYING(20) NOT NULL,
...
PRIMARY KEY(id)
);
CREATE TABLE ConceptFeatureRelationship (
concept_id CHARACTER VARYING(20) NOT NULL,
feature_id BIGINT NOT NULL,
value CHARACTER VARYING(100),
PRIMARY KEY(concept_id, feature_id),
FOREIGN KEY (concept_id) REFERENCES Concept(id) ,
FOREIGN KEY (feature_id) REFERENCES Feature(id)
);
So a "Concept" may be CAR, a CAR's feature may be "color" and "red" may be the value characterizing the relationship between a particular instance of car and its color (please, its only an example, don't take it literally).
I'have found no means to represents this scenario with Hibernate in a simple way: the most direct solution seems to be moving the "value" field into the Feature table. However the drawback is a lot of data redudancy if a feature has much more fields and only one is actually characterizing the relationship.
Relationships with characterizing attributes is not a case so strange in E/R data modeling.
Any idea or suggestion?
Thanks a lot
Fabrizio Casali
|