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: Implementors of an interface that have different tables
PostPosted: Thu Nov 30, 2006 8:29 am 
Beginner
Beginner

Joined: Mon Apr 24, 2006 10:42 am
Posts: 23
Hi all,

We are struggling with a design problem, and would appreciate any insights:

In our domain model, we have a Problem domain object, which has a Cause. Cause may be one of a variety of things, such as a User, Process etc. The domain objects that may be a cause of a problem, have nothing in common! They are completely unrelated classes, and are kept in different tables in the database (e.g. USER_T, PROCESS_T etc.). We therefore thought that it makes sense for the Problem object to hold a reference to the Cause interface, and have each of the potential "causes" implement that interface.

But here's the problem: how do we map the relationship between Problem and the various implementors of the Cause interface?

We found in the Hibernate documentation an example for mapping a "table per subclass" hierarchy using <union-subclass>, which does not require a table for the superclass (which, in our case is the Cause interface). However, this assumes that the subclasses are mapped inside the mapping of the superclass, which is not our case: the classes that implement the Cause interface are first-class domain-objects in our application, and are already mapped in their own Hibernate mapping files.

Is there a solution? Is there maybe a different approach for such a design?

Thanks,
Naaman


Top
 Profile  
 
 Post subject: Second try...
PostPosted: Thu Dec 07, 2006 9:28 am 
Beginner
Beginner

Joined: Mon Apr 24, 2006 10:42 am
Posts: 23
Has anyone ever did something like this?
We'd be thankful for a tip.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 28, 2006 7:42 am 
Newbie

Joined: Thu Dec 28, 2006 7:21 am
Posts: 1
Hello Nlif and others,

Same problem here... I'm implementing an e-commerce site and i want the basket to be able to hold a variety of objects from totally unrelated classes. Therefore i defined an interface `Basketable' and a basket contains a Set of Basketable objects. Basketable declares certain functions (such as getPrice, getDescription), but contains no member variables. For this reason, and because the classes that implement basketable can be part of other - unrelated - class hierarchies, it is not logical to map Basketable and its implementors as a class hierarchy.

When loading a persistent basket with hibernate, i want the interface functions available on the objects in the basket and i do not care about the rest. `Hibernate in Action' and the online docs do not explain if and how to deal with this situation, at least not clearly. (Maybe it would be a good idea to included a section `dealing with interfaces' in the manual.)

Any ideas would be appreciated.

Best regards

MCW


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.