-->
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.  [ 7 posts ] 
Author Message
 Post subject: Optimizing Root Persistent Class pattern
PostPosted: Wed Oct 13, 2004 10:20 am 
Regular
Regular

Joined: Thu Oct 07, 2004 4:45 pm
Posts: 92
Hi.

I was reading through the Design Patterns section on the site and found the one called Root Persistent Class. This sounds like exactly what I want to do. I want to have an abstract class at the top of my hierarchy with common attributes that all of my persistent classes share. I don't want these attributes in their own table, though, for performance reasons.

What I want to know is if there is a way to write the mapping files so that I don't have to copy/paste all of the common attributes into every class mapping that extends my abstract class.

I tried to get creative with XML external entities. I created a file containing an XML fragment that maps the common attributes, and then I tried to include the fragment using entity references in the mapping files of the subclasses. Unfortunately, it didn't work because the SAX parser that reads in the mapping file doesn't have a base URI defined, so I couldn't use a relative path to my included entity file. (I don't want to hard-code an absolute path, unless I can somehow tell it to search the classpath. I also don't want to modify the Hibernate source code.)

Am I out of luck? Has anyone else tried to do this?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 14, 2004 4:02 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
I haven't tried it - but an alternative is to have ant generate it for you with some replace tokens.....(just a workaround)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 14, 2004 3:13 pm 
Regular
Regular

Joined: Tue Sep 28, 2004 6:34 pm
Posts: 50
Try:
Code:
   <class name="MyObjectInterface" table="Object">
      ... properties
      
      <joined-subclass name="SubObject" table="SubObject">
            ....
      </joined-subclass>
   </class>


and in Java define:

abstract class MyObject implements MyObjectInterface
...
class SubObject extends MyObject

this should do the trick - You will have common base (also in database).

Lukasz


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 14, 2004 3:21 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
But he explicitly stated: " I don't want these attributes in their own table, though, for performance reasons." ....so joined-subclass won't do it for him ;)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 14, 2004 3:56 pm 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
You can also play with the dom tree in memory. I solved a similar problem this way:

1. Get a org.w3c.dom.Document of the cfg.xml
2. Creat a org.w3c.dom.Document for every hbm.xml mapping in the cfg.xml and remove the hbm.xml entries from the cfg.xml Document.
3. Feed the cfg.xml Document to Configure.
4. Patch each hbm.xml Document and feed it to Configure.

HTH
Ernst


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 14, 2004 8:05 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 8:07 pm
Posts: 229
Location: Brisbane, Australia
We do exactly this, but we use XDoclet and it handles the inheritance of the mapping attributes for us.

_________________
Cheers,
Shorn.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 21, 2004 1:58 pm 
Regular
Regular

Joined: Thu Oct 07, 2004 4:45 pm
Posts: 92
Thanks. Too much work. I just combined them all into one file, and now I'm using internal entities. Works fine, although this file will grow to be quite big now.


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