-->
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: many-to-many with order
PostPosted: Tue Oct 25, 2005 3:32 pm 
Newbie

Joined: Tue Oct 25, 2005 3:20 pm
Posts: 3
All,

I want to create a many-to-many mapping with an order so I can map images to categories and also specify the order of the images in the categories.

My example mapping files

Category.hbm.xml:
<hibernate-mapping>

<class name="Category"
table="CATEGORY"
mutable="true">

<cache usage="transactional"/>

<id name="id" column="CATEGORY_ID"
unsaved-value="null">
<generator class="native"/>
</id>

<property name="name"
column="CATEGORY_NAME"
update="true"
length="100"/>

</class>

</hibernate-mapping>

Image.hbm.xml
<hibernate-mapping>

<class name="Image"
table="IMAGE"
mutable="true">

<cache usage="transactional"/>

<id name="id" column="IMAGE_ID"
unsaved-value="null">
<generator class="native"/>
</id>

<property name="name"
column="IMAGE_NAME"
update="true"
length="100"/>
</class>

</hibernate-mapping>


and my table schema should become like this:

IMAGE
-----
IMAGE_ID
IMAGE_NAME


CATEGORY
-------
CATEGORY_ID
CATEGORY_NAME


IMAGE_CATEGORY
-------------
IMAGE_ID
CATEGORY_ID
ORDER

Who has a suggestion or example for me?
Thanks in advance.
Niels


Top
 Profile  
 
 Post subject: how about link class?
PostPosted: Tue Oct 25, 2005 4:08 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
I guess you can have ImageCategoryLink class that will be simple class like
Class ImageCategoryLink {
Category category;
Image image;
}

And then simply retrieve necessary images by HQL like
“from ImageCategoryLink icl where icl.category.id = ? order by icl.image.name”
or
“from ImageCategoryLink icl order by icl.category.name , icl.image.name”
or
“from ImageCategoryLink icl order by icl.image.name , icl.category.name ”


and mapping of ImageCategoryLink is simple many-to-one
http://www.hibernate.org/hib_docs/v3/re ... -manytoone

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


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.