-->
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.  [ 9 posts ] 
Author Message
 Post subject: Complex mapping question
PostPosted: Sat Feb 21, 2004 1:52 pm 
Newbie

Joined: Sat Feb 21, 2004 1:34 pm
Posts: 12
Location: Denver, Colorado
Greetings,

I have a fairly complex mapping problem. I have one solution for it but it is not as elegant as I would like. Hopefully someone on here has run into a similar problem and found a cleaner solution.

Having said that, I have four tables that are linked together with foreign keys, etc.

Parent
-------------
id:long
(other junk)

MetaFields
----------------
id:long
parentClass:String
fieldName:String

MetaOptions
----------------
id:long
metafieldsID:long
value:String

MetaValues
----------------
id:long
parentid:long
metafieldsid:long
metaoptionsid:long
freeformvalue:String

Hopefully that is clear. Basically Parent is the main object that I want to load. The other objects should get loaded automatically. MetaFields is a direct child of parent joined by parent's actual class name. MetaOptions is a child of MetaFields with a simple foreign key. The hard table is the MetaValues table. It is linked to Parent, MetaFields and MetaOptions.

The initial solution I have come up with is to link Parent --> MetaFields --> MetaOptions as normal and then load MetaValues as a direct child of Parent. Then just use some coding in the Parent object to link it into MetaFields. I would rather having Hibernate Link the MetaValues in but I am not sure if it is possible.

I look forward to any suggestions anyone may have (other than changing the table structures which is not an option).

Thanks,

Marcus[b][/b][b][/b]


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 24, 2004 2:57 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
MetaFields -one-to-many-> matavalue
Does it fit ?

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 24, 2004 3:03 pm 
Newbie

Joined: Sat Feb 21, 2004 1:34 pm
Posts: 12
Location: Denver, Colorado
It also needs to link to the parent. It is a three table join between parent and metafields to metavalues.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 24, 2004 5:39 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
So i don't get your needs

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 24, 2004 5:43 pm 
Newbie

Joined: Sat Feb 21, 2004 1:34 pm
Posts: 12
Location: Denver, Colorado
What I was/am asking is if there is an easier way to do this mapping.

Ideally, when the parent object is loaded I would like for the MetaFields to be mapped into a set (easy) and for each metafield its MetaOption children loaded(easy) AND the current metavalue for that field and parent (hard).

I have the easy parts already, I just want to know if there is a way to do the part I have flagged as hard. In the above example, MetaField would have a set of MetaOptions and it would have ONE MetaValue (which is the selected value).

Hopefully that makes it clearer.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 25, 2004 6:46 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
What are the relationships

Parent 1-n MetaFields
MetaFields 1-n MetaOptions

Thus 1 MetaOptions is binded to 1 parent and binding MetaOptions 1-n MateValues will od the job

If there is a n-n relation between Parent and MEtaFields, then ther is no easy way I guess.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 25, 2004 7:19 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
i think we have the same mdel here, names are in french sorry...
We have n CARACTERISTIQUES defined
We have n PRODUCTS defines
But for 1 PRODUCT and 1 CARACTERISTIQUE we have only one VALEUR_CARACTERITIQUE

hoping our mapping files help you....
<hibernate-mapping>
<class name="com.auchan.balisage.bo.produit.Produit" table="PRODUIT">
<id column="ID_PRODUIT" name="idProduit" >
<generator class="sequence">
<param name="sequence">SEQ_PRODUIT</param>
</generator>
</id>
.....
<bag name="valeurs" lazy="true" inverse="true" cascade="all" table="VALEUR_CARACTERISTIQUE">
<key column="ID_PRODUIT"/>
<one-to-many column="ID_PRODUIT" class="com.auchan.balisage.bo.segmentation.ValeurCaracteristique"/>
</bag>
</class>
</hibernate-mapping>

<hibernate-mapping>
<class name="com.auchan.balisage.bo.segmentation.Caracteristique" table="CARACTERISTIQUE">
<id column="ID_CARACTERISTIQUE" name="idCaracteristique" >
<generator class="sequence">
<param name="sequence">SEQ_GROUPE_CARACTERISTIQUE</param>
</generator>
</id>
.....
<bag name="valeurs" lazy="true" inverse="true" cascade="all" table="VALEUR_CARACTERISTIQUE">
<key column="ID_CARACTERISTIQUE"/>
<one-to-many column="ID_CARACTERISTIQUE" class="com.auchan.balisage.bo.segmentation.ValeurCaracteristique"/>
</bag>
</class>
</hibernate-mapping>

<hibernate-mapping>
<class name="com.auchan.balisage.bo.segmentation.ValeurCaracteristique" table="VALEUR_CARACTERISTIQUE">
<composite-id>
<key-many-to-one name="produit" class="com.auchan.balisage.bo.produit.Produit" column="ID_PRODUIT"/>
<key-many-to-one name="caracteristique" class="com.auchan.balisage.bo.segmentation.Caracteristique" column="ID_CARACTERISTIQUE"/>
</composite-id>
....
<property name="valeurBlob" column="OBJECT" />
</class>
</hibernate-mapping>



Once you have this, you have to be ok with HQL and managing objects on your app


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 25, 2004 12:18 pm 
Newbie

Joined: Sat Feb 21, 2004 1:34 pm
Posts: 12
Location: Denver, Colorado
Very interesting. If I am reading your mapping file correctly, you have a many-to-one from value to characteristic and a many-to-one from value to product.

My question is, when you load your product (which I am assuming is your parent object) does the characteristic only receive the values that are linked to the product?

If so then yes this would solve my situation perfectly.

Thank you for taking the time to post that mapping file.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 25, 2004 12:53 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
you're welcome

product.getCharacteristicsValues returns the collection of all the values needed to describe this objects but it is not a charactericticValue linked to the product AND CHARACTERISTIC you want.
To do that you can query

"from com.xxx.characteristicsValue c
where c.product.id = :productId" --> the product you want
and c.characteristic = :characteristicId" --> the characteristic you need

(you can also use session.load (characteristicsValue.class, serializable x), x being the representation of the compisite id which i supposed is composed by id_product and id_caracteristic...)

This query will return only one characteristicsValue cv.
From cv, you also wil be able to get your product and characteristics ....


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 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.