-->
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 advice needed: different collections to same table
PostPosted: Tue May 31, 2005 9:58 am 
Newbie

Joined: Tue May 31, 2005 8:57 am
Posts: 10
Hibernate version: 3.0.5

Hi,

I'd like some help mapping a particular class and it's relations. The class is supposed to look like this:
Code:
public class Term {
   private Set<Term> someTerms;
   private Set<Term> someOtherTerms;
   private Set<Term> someMoreTerms;
}

The Term class is mapped to the TERM table and the collections should also be mapped to the TERM table. But they should also be split into separate collections. Can this be accomplished? I could not find any information on this.

Regards,
Ronald Wildenberg.


Top
 Profile  
 
 Post subject: Discriminators
PostPosted: Tue May 31, 2005 1:55 pm 
Beginner
Beginner

Joined: Thu Nov 11, 2004 12:18 pm
Posts: 37
Location: Baltimore, MD
Yes, I've been able to do what you're talking about. Look in the guide for "discriminators". Basically you need a column in the table to differentiate which collection a row in the table will belong to.

In the case which I'm working with, each collection is mapped to a different class, each defining their discriminator value. Each of these classes extend from a superclass that defines all of the common fields in that table, as well as the column name and type of the discriminator column.


We use XDoclet, so here's an example of class-level tags for defining them:

<Superclass>
@hibernate.discriminator
column="type"
type="string"

<Subclass1>
@hibernate.subclass
discriminator-value="A"

<Subclass2>
@hibernate.subclass
discriminator-value="B"

<Subclass3>
@hibernate.subclass
discriminator-value="C"


When you map the collections, just map one collection to Subclass1, one to Subclass2, and one to Subclass3. They will all map to the same table, and the discriminator is taken care of automatically.

_________________
-Chris


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.