-->
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: Can I "override" default persistent class with sub
PostPosted: Fri Dec 02, 2005 10:00 am 
Regular
Regular

Joined: Tue Oct 26, 2004 3:54 pm
Posts: 60
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.0.5

I was wondering if anyone ever had to do the following :

Standard product, using Hibernate, with let's say 20 classes mapped and defined.

Need to customize the product often, creating custom subclasses of the original classes - which usually have an extended database table.

So let's say I have StandardObject, which is mapped and works correctly, and CustomObject which extends StandardObject.

I'm really trying to understand how I can make a mapping for CustomObject which extends and substitutes the original mapping, so that a query like "from StandardObject" actually retrieves instances of CustomObject.

It's a pattern we had in the previous framework, called substitution - usually managed by a configured factory.

I hope there is some solution...

Thanks in advance,

Giulio


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 02, 2005 11:09 am 
Regular
Regular

Joined: Tue Oct 28, 2003 8:25 am
Posts: 72
Location: Belgium
Did you have a look at the subclass strategies ?

You could create your new CustomObject extending StandardObject as expected and then create a mapping file using

Code:
<subclass> (Table per class hierarchy)

or

Code:
<joined-subclass> (Table per subclass)

instead of the <class> tag.

Read carefully the doc's chapter 10:

http://www.hibernate.org/hib_docs/v3/re ... strategies


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 02, 2005 11:24 am 
Regular
Regular

Joined: Tue Oct 26, 2004 3:54 pm
Posts: 60
Hi lorban,

I carefully looked at the feature you mentioned, and I even wrote a testcase.

The <subclass> approach is useful when subclasses of a superclass live together in the table. My situation is different : the subclass (only one exists) SUBSTITUTES the superclass.

I would except then the persistence layer to retrieve instances of the substitute and not of the original class, if a manner to do so exists.

Any idea ?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 02, 2005 11:39 am 
Regular
Regular

Joined: Tue Oct 28, 2003 8:25 am
Posts: 72
Location: Belgium
You could probably achieve that using filters:

http://www.hibernate.org/hib_docs/v3/re ... te-filters

You would have to create a "type" column in the parent's table in case of a <joined-subclass> mapping or re-use the discriminator for a <subclass> one.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 02, 2005 12:04 pm 
Regular
Regular

Joined: Tue Oct 26, 2004 3:54 pm
Posts: 60
lorban wrote:
You could probably achieve that using filters:

http://www.hibernate.org/hib_docs/v3/re ... te-filters

You would have to create a "type" column in the parent's table in case of a <joined-subclass> mapping or re-use the discriminator for a <subclass> one.


Actually my pattern has no joined-subclasses or discriminator.

The table is the same, the subclass would substitute interely the superclass.

I think the entity-name attribute in <class> mapping is the most near solution.


Thanks,

Giulio


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.