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.  [ 3 posts ] 
Author Message
 Post subject: retrieving a list of specific type on table-per-hierarchy
PostPosted: Tue Aug 28, 2007 10:59 am 
Newbie

Joined: Tue Aug 28, 2007 10:45 am
Posts: 1
I have a legacy table that resembles table-per-hierarchy. I can map different subclasses to that table using @Inheritance(strategy = InheritanceType.SINGLE_TABLE) and @DiscriminatorColumn.

However I want to map one-to-many association to this table but only return a list of a specific class.

Is this possible?

Below is an example of what I'm trying to do. Unfortunately, the database schema is production schema, so I don't have much control in changing it, but I want to leverage object-oriented domain model as much as possible.

Thanks for any help.

=========================
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "TYPE", discriminatorType = DiscriminatorType.STRING)
@DiscriminatorValue("PET")
public abstract class Pet {
}
=========================
@Entity
@DiscriminatorValue("DOG")
public class Dog extends Pet {
}
=========================
@Entity
@DiscriminatorValue("CAT")
public class Cat extends Pet {
}
=========================
@Entity
public class PetOwner {
private List<Dog> dogs;
private List<Cat> cats;

@OneToMany
public List<Dog> getDogs() {
}

@OneToMany
public List<Cat> getCats() {
}
}
=========================


Top
 Profile  
 
 Post subject: Re: retrieving a list of specific type on table-per-hierarch
PostPosted: Tue Aug 28, 2007 4:10 pm 
Beginner
Beginner

Joined: Mon Aug 27, 2007 8:10 am
Posts: 37
kogori wrote:
I have a legacy table that resembles table-per-hierarchy. I can map different subclasses to that table using @Inheritance(strategy = InheritanceType.SINGLE_TABLE) and @DiscriminatorColumn.

However I want to map one-to-many association to this table but only return a list of a specific class.

Is this possible?



We have similar needs.
So far we are going to have protected collection Pets which is then used as a source for poulating transient collections Dogs and Cats.

May be there is a better, more 'hibernated' solution.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 29, 2007 12:04 am 
Beginner
Beginner

Joined: Fri May 18, 2007 10:28 am
Posts: 48
Location: Madison, WI
I think, if you declare List of Dog/Cat in petowner class. Of course corresponding entry in hbm file as well. Make sure lazy-init is set to false. Let me know if that fixes things.

_________________
Please rate if it helped


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