-->
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.  [ 6 posts ] 
Author Message
 Post subject: Class discriminator not being picked up
PostPosted: Mon Apr 18, 2005 12:31 pm 
Senior
Senior

Joined: Tue Mar 02, 2004 6:17 pm
Posts: 151
I get this exception on startup:

Code:
org.hibernate.MappingException: No discriminator found for com.be.desktopbeautifier.server.DefaultTheme. Discriminator is needed when 'single-table-per-hiearchy' is used and a class has subclasses


Here is my mapping file:
Code:
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping
>
    <class
        name="com.be.desktopbeautifier.server.AbstractTheme"
        table="theme"
        discriminator-value="AbstractTheme"
    >

        <id
            name="id"
            column="id"
            type="int"
            unsaved-value="0"
        >
            <generator class="native">
              <!-- 
                  To add non XDoclet generator parameters, create a file named
                  hibernate-generator-params-AbstractTheme.xml
                  containing the additional parameters and place it in your merge dir.
              -->
            </generator>
        </id>

        <version
            name="version"
            column="version"
            type="int"
        />

        <set
            name="children"
            lazy="false"
            cascade="all"
            sort="unsorted"
        >

            <key
            >
                <column
                    name="parent_id"
                    not-null="true"
                />
            </key>

            <one-to-many
                  class="com.be.desktopbeautifier.server.AbstractTheme"
            />
        </set>

        <property
            name="name"
            type="java.lang.String"
            update="true"
            insert="true"
            column="name"
            not-null="true"
        />

        <!--
            To add non XDoclet property mappings, create a file named
                hibernate-properties-AbstractTheme.xml
            containing the additional properties and place it in your merge dir.
        -->
        <subclass
            name="com.be.desktopbeautifier.server.DefaultTheme"
            discriminator-value="DefaultTheme"
        >

       <!--
               To add non XDoclet property mappings, create a file named
                hibernate-properties-DefaultTheme.xml
      containing the additional properties and place it in your merge dir.
       -->
        </subclass>
    </class>
</hibernate-mapping>


Clearly "discriminator-value" is specified. Any ideas why this does not work?

Thank you,
Gili


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 18, 2005 1:09 pm 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
I think you missed to define the discriminator column.

For example:
Code:
<discriminator column="discriminator" type="string"/>


See 5.1.6 in the documentation.

Best regards
Sven


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 18, 2005 1:19 pm 
Senior
Senior

Joined: Tue Mar 02, 2004 6:17 pm
Posts: 151
sven wrote:
I think you missed to define the discriminator column.

For example:
Code:
<discriminator column="discriminator" type="string"/>


See 5.1.6 in the documentation.

Best regards
Sven


Odd, that did it. Thanks!

The funny thing is that both in Hibernate Annotations and XDoclet, if you don't specify the discriminator a default value is supposed to get used. The column is supposed to default to "type" and the value to the fully-qualified name of the class. For some reason, however, when using XDoclet you are required to specify these values manually.

Gili


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 18, 2005 1:50 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
If you don't specify the column attribute in HBM, the column name equals to "class".
If you don't specify the @DiscriminatorColumn using annotations, the column name equals to "TYPE".

discrimiantor value default to the fully qualified class name.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 18, 2005 2:12 pm 
Senior
Senior

Joined: Tue Mar 02, 2004 6:17 pm
Posts: 151
emmanuel wrote:
If you don't specify the column attribute in HBM, the column name equals to "class".
If you don't specify the @DiscriminatorColumn using annotations, the column name equals to "TYPE".

discrimiantor value default to the fully qualified class name.


Right, but the question is what happens if you don't specify the discriminator in the mapping file? That is, do the defaults get applied by Hibernate or by the Annotations/XDoclet layer? My guess is the latter.

Thanks,
Gili


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 19, 2005 2:09 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
There is not discriminator default for the hbm layer.

_________________
Emmanuel


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