-->
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.  [ 1 post ] 
Author Message
 Post subject: Many-to-many association with discriminator
PostPosted: Fri Mar 11, 2005 7:40 am 
Beginner
Beginner

Joined: Fri Mar 12, 2004 1:12 pm
Posts: 25
Location: Minsk, Belarus
Preambula:
I have a number of objects such as Product, Document, etc..
It is needed to classify them by some characteristic.

Different users can use their own model to classify object. They can classify by UNSPSC, eClass or whatever else.
The examples of Classification is "teapot", "cell phone", "books with hard cover", whatever.
Object maps to Classification in relationship of M:N as it is possible to classify Object by different classification models.


Now DB schema responsible for classification looks like
CLASSIFICATION (Teapot, book, car, ...)

PRODUCT
PRODUCT2CLASSIFICATION

DOCUMENT
DOCUMENT2CLASSIFICATION

...

SOMEOBJECT
SOMEOBJECT2CLASSIFICATION

It is inconveniently to keep many linkage table with ConcreteObject-Classification relationship.
I would like to make more consistent DB model and move all Object-Classification data to one table.

Something like that

OBJECT2CLASSIFICATION
object_type -- discriminator ('P' for product, 'D' for document, 'P' for Person ...)
object_sn -- Object Identifier (ProductSN, DocumentSN)
classificationSN


And at the end code should looks like
productObj.getClassifications()
--Hibernate : select from obj2classific where object_type='P' and object_sn = ?
documentObj.getClassifications()
--Hibernate : select from obj2classific where object_type='D' and object_sn = ?

productObj.getClassifications().add(classObje)
--Hibernate : insert into obj2classific (object_type, object_sn, classification_sn) values ('P',?,?)


I need only unidirectional relationship, at least for now.
It looks like many-to-many association with discriminator.
Does Hibernate allows it or other way to solve polymorphic many-to-many relationship??
What is the best practice in such case???


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

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.