-->
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: Is it possible to map an abstract class?
PostPosted: Fri Jul 02, 2004 12:41 pm 
Newbie

Joined: Fri Jul 02, 2004 12:13 pm
Posts: 2
Can anyone tell me if it is possible to map an abstract class? It doesn't look like it's possible, but maybe I'm doing something wrong. For example, I want to do something like this:

Code:
<class name="BaseClass" discriminator-value="BaseClass">

        <id>...</id>
        <discriminator/>

        <property ... />
        <property ... />
        <property ... />

        <subclass name="ConcreteClassA" .../>
        <subclass name="ConcreteClassB" .../>
        <subclass name="ConcreteClassC" .../>

</class>


where BaseClass is abstract. It looks like Hibernate requires that BaseClass be concrete (and also have a no-arg constructor, etc.) even though there are no actual records with that type. I can, of course, map each subclass separately, but then I have to duplicate the properties. It would be more convenient if I could map it as above.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 15, 2004 3:27 am 
Newbie

Joined: Thu Jul 15, 2004 2:02 am
Posts: 2
Hi,
We had a similar problem. I think it is not possible to have an abstract class as in the Hibernate it tries to get a new instance of the class ( AbstractClass ab = new AbstractClass and it fails there).
So what we are doing is, have that as a normal class with all the methods and getter / setter for all the fields and the other classes extending this class.The other classes will have just their respective getter / setters.
Also there will be only one hbm file for the parent class.
That way we can avoid duplication


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 15, 2004 10:19 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Of course you can, just as explaine here http://www.hibernate.org/hib_docs/reference/en/html/inheritance.html


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.