-->
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.  [ 9 posts ] 
Author Message
 Post subject: How many levels of inheritance allowed with polymorphism?
PostPosted: Wed May 19, 2004 1:11 am 
Newbie

Joined: Tue Oct 14, 2003 2:07 pm
Posts: 10
Location: Berkeley, CA
Is the following interpretation of the docs correct? Hibernate 2.1.3 allows
1. Only two levels of inheritance with joined subclass
(i.e. can't declare a joined subclass extending another joined subclass)
2. Allows at max 3 levels of inheritance when mixing table-per-concrete-class with either joined subclass or table per class.

Thanks much.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 19, 2004 11:22 am 
Regular
Regular

Joined: Wed May 12, 2004 3:03 am
Posts: 51
Location: France
Hi,

What I'm sure, is you can have as much as you want/need joined subclasses. While you have enough discriminator values... ;o)

About the second question, I can't help you... sorry.

Charles


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 19, 2004 1:36 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
2. no mix allowed (except for the root class which does not really count)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 19, 2004 5:51 pm 
Newbie

Joined: Tue Oct 14, 2003 2:07 pm
Posts: 10
Location: Berkeley, CA
Emmanuel,

Could I ask you to elaborate? Is 2 the maximum level allowed or are you saying in my point 2, no mixing is allowed? I know one can't mix "table-per-hierarchy" with "table per subclass", but documentation suggests you can mix table-per-concrete-class with another strategy:

" Since the subclasses(..for table-per-concrete-class strategy..) are each mapped in their own <class> element (and since Payment is just an interface), each of the subclasses could easily be part of another table-per-class or table-per-subclass inheritance hierarchy"

Thanks again,
Hster


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 29, 2004 7:04 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Hum, this is due to the particular usage of <any>.
Forget that, this is useful is very specific cases. In 99,9% of the cas (ie non any usage), mix is not allowed

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 29, 2004 8:29 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Separate <class> mappings may be mixed in a hierarchy. <joined-subclass> and <subclass> may not be mixed within a <class>. Listen, this is enforced by the DTD, and you can't write an invalid mapping!

There is, of course, no limit to the depth of inheritance in Hibernate.


Top
 Profile  
 
 Post subject: Limit in levels of inheritance with joined-subclass
PostPosted: Mon Aug 09, 2004 6:25 pm 
Newbie

Joined: Wed Mar 24, 2004 7:40 pm
Posts: 18
As I understand the above, this question:

Quote:
1. Only two levels of inheritance with joined subclass
(i.e. can't declare a joined subclass extending another joined subclass)


was answered with this answer:

Quote:
There is, of course, no limit to the depth of inheritance in Hibernate.


I am trying to create a mapping that has a single base class, a subclass, and a sub-subclass, and I have seemed to encounter the problem that there is no way to map the sub-subclass without getting a MappingException at code-generation time. Say C inherits from B inherits from from A. When code generating C, I get the following error even if B generates successfully:

Code:
net.sf.hibernate.MappingException: Cannot extend unmapped class com.twcaustin.intranet.myforms.model.B


I am using Oracel 9, Hibernate 2.1.6, with the following mapping files:

A.hbm.xml
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping package="com.twcaustin.intranet.myforms.model">
    <class name="com.twcaustin.intranet.myforms.model.A" table="A">
        <id
            name="id"
            type="java.lang.Long"
            column="ID"
            unsaved-value="null"
            access="property">
            <generator class="sequence">
                <param name="sequence">seq_ID</param>
            </generator>
        </id>
        <version name="name" type="string" column="name" unsaved-value="null" />
    </class>
</hibernate-mapping>


B.hbm.xml
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping package="com.twcaustin.intranet.myforms.model">
   <joined-subclass name="com.twcaustin.intranet.myforms.model.B"
       extends="com.twcaustin.intranet.myforms.model.A"
       table="B" >
       <key column="ID" foreign-key="id" />
       <property name="title" column="TITLE" type="string" />
   </joined-subclass>
</hibernate-mapping>



C.hbm.xml
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping package="com.twcaustin.intranet.myforms.model">
   <joined-subclass name="com.twcaustin.intranet.myforms.model.C"
       extends="com.twcaustin.intranet.myforms.model.B"
       table="C" >
       <key column="ID" foreign-key="id" />
       <property name="ln" column="LN" type="string" />
   </joined-subclass>
</hibernate-mapping>


I am using an ANT task that looks like this, which I have been using successfully to generate other Hibernate classes for some time:

Code:
<java classname="net.sf.hibernate.tool.hbm2java.CodeGenerator" fork="true">
            <classpath refid="hibernate.classpath" />
            <classpath location="${hbmdata.jar}" />
            <arg value="--output=${gensrc}" />
            <arg line="${hbm.files}" />
        </java>


here is the complete stack trace for the error given by the generator:

Code:
[java] net.sf.hibernate.MappingException: Cannot extend unmapped class com.twcaustin.intranet.myforms.model.B
[java]     at net.sf.hibernate.tool.hbm2java.CodeGenerator.handleClass(CodeGenerator.java:137)
[java]     at net.sf.hibernate.tool.hbm2java.CodeGenerator.main(CodeGenerator.java:109)


I have found this error in the bug database, but it says it was fixed 22/Jul/04 05:12 PM, which is before the release of 2.1.6:

http://opensource.atlassian.com/project ... se/HB-1097

Is it fixed, or am I doing something wrong?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 27, 2004 9:03 am 
Beginner
Beginner

Joined: Tue Oct 07, 2003 4:41 am
Posts: 21
I have a 3 level class hierarchy using <joined-subclass> and it is working fine. Using Hibernate 2.1.4

Unfortunately I can't see anything wrong with your mapping files, so this reply doesn't help you much.

The only thing I'd suggest, is that based on the error message, it looks like maybe it's reading the class C mapping before it gets to the class B mapping. Is there any chance it's getting them in the wrong order?

John


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 29, 2004 9:27 am 
Expert
Expert

Joined: Tue Oct 05, 2004 9:45 am
Posts: 263
it is fixed.
I'm using hibernate 2.1.6 and it works perfectly. The only thing you need to do is to pass both xml-Mapping-Files to the CodeGenerator ...

gtx
curio


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