-->
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.  [ 5 posts ] 
Author Message
 Post subject: Is there a direct mechanism to map a polymorphic collection?
PostPosted: Tue Jan 18, 2005 11:09 pm 
Newbie

Joined: Thu Dec 09, 2004 10:48 pm
Posts: 5
Is there a direct mechanism in Hibernate that can be used for mapping a collection of polymorphic objects? My limited knowledge of the platform is that (a) Hibernate is always surprising me with what it implements up front, but (b) This mapping is not "relational" in the classical sense of the word, so an Object Relational Mapping is only a partial answer.

For example:

Code:
/* "Master" level of master/detail view
*/
class Assembly {
    Job job;
    String name;

    ArrayList items;    /* This is a polymorphic collection */

// ... snip ...
}

/* The ArrayList "items"  may contain instances of all of these at any time */

class Pipe;
class Valve;
class CastFitting;
class ForgedFitting;
class ExtrudedFitting;
class Insulation;
class StructuralSteel;
class ConcreteCasting;
[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 18, 2005 11:16 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Whats your actual problem?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 19, 2005 9:15 am 
Newbie

Joined: Thu Dec 09, 2004 10:48 pm
Posts: 5
At this time, I am designing the system at a high level. I have used Hibernate successfully in projects where there is a traditional relational model, and I have wroeked out how Hibernate can make coding a polymorphic collection loader much easier.

But, if it is possible, I would like to stick strictly to configurations for defining the collection relationship.

As it is, with my current understanding of Hibernate, I would need an intermediate stub piece to hold lookup information for every item in the collection. The stub would say what instance ID (aka primary key), and what class (aka table), and the loader class would use Hibernate functionality to look up the actual class from the intermediate stubbed data.

I would prefer to use a configuration only and avoid building the loader class, the intermediate lookup stubs and stub table.

At this point, it is still strictly a design problem - nothing has been laid in code or DDL.

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 19, 2005 10:51 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
I don't really understand your conclusions, but what you need is a common interface you can use as the target for the association, e.g. a common superclass.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 19, 2005 7:21 pm 
Newbie

Joined: Thu Dec 09, 2004 10:48 pm
Posts: 5
If I understand you, then if all of my classes descended from, say, LineItem, and the reference was defined to LineItem, then Hibernate will correctly populate the collection of all pertinent classes (aka from all tables).

So,
Code:
class LineItem
{
    private Assembly owner;
    private int sequence;
}


then if the other classes all extend LineItem, and the Hibernate mapping is to LineItem, the items in Assembly will be correctly populated and managed by the Hibernate environment.

This is simpler than I had hoped for, if it is true.

Thanks!


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