-->
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.  [ 2 posts ] 
Author Message
 Post subject: Mapping N:M relationship with characterizing attributes
PostPosted: Mon Jul 28, 2008 4:21 am 
Newbie

Joined: Mon Jul 28, 2008 4:14 am
Posts: 3
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


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 28, 2008 7:04 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
One options I often see used it to create two one to many relationships, rather than one many to many relationships. It the becomes much easier to add such attributes.

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


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

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.