-->
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.  [ 4 posts ] 
Author Message
 Post subject: WrongClassException
PostPosted: Thu Nov 27, 2003 5:51 am 
Newbie

Joined: Wed Nov 19, 2003 5:30 am
Posts: 9
Hello.

Please take a look at my mapping. I've always get a WrongClassException:

10:34:14,760 WARN [ProjektHelperImpl] Projekt 2 nicht gefunden net.sf.hibernate.WrongClassException: Object with id: 2 was not of the specified subclass: PlanKostenImpl (loaded object was of wrong class)

<hibernate-mapping>
<class name="MarketingkostenImpl" table="mkz_marketingkosten" polymorphism="explicit" discriminator-value="B">

<discriminator column="type" type="java.lang.String" length="2"/>

<property ... />

<subclass name="IstKostenImpl" discriminator-value="I">
<property .../>
</subclass>

<subclass name="PlanKostenImpl" discriminator-value="P">
<property .../>
</subclass>

</hibernate-mapping>


<hibernate-mapping>
<class name="ProjektImpl" table="mkz_projekt">

<property .../>

<set name="istKosten" lazy="false" inverse="false" cascade="all" sort="unsorted">
<key column="projekt_id"/>

<one-to-many class="IstKostenImpl"/>
</set>

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

<key column="projekt_id"/>

<one-to-many class="PlanKostenImpl"/>
</set>

<one-to-one name="vertriebsBudget" class="MarketingkostenImpl" cascade="all" outer-join="auto" constrained="false"

</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 27, 2003 5:58 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Use:

Code:
<hibernate-mapping>
    <class name="ProjektImpl" table="mkz_projekt">

      <property .../>

      <set name="istKosten" lazy="false" inverse="false" cascade="all" sort="unsorted" where="type='I'">
              <key column="projekt_id"/>

              <one-to-many class="IstKostenImpl"/>
     </set>

        <set
            name="planKosten" lazy="false" inverse="false" cascade="all" sort="unsorted"  where="type='P">

              <key column="projekt_id"/>

              <one-to-many class="PlanKostenImpl"/>
        </set>

        <one-to-one name="vertriebsBudget" class="MarketingkostenImpl" cascade="all"  outer-join="auto" constrained="false"

</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 18, 2007 8:26 am 
Newbie

Joined: Wed Apr 18, 2007 7:22 am
Posts: 4
Another approach is to use force="true" in the discriminator element: <discriminator column="..." force="true" />. This causes Hibernate to include a condition on the discriminator column in the Where clause of the generated SQL. Moreover, the condition will include all subclasses further down the inheritance hierarchy, so you don't have to manually update the Where clause every time you add a new subclass of the class you intend to retrieve.

This feature is also available through the Hibernate annotation @org.hibernate.annotations.ForceDiscriminator but it is not part of the JPA standard.


Top
 Profile  
 
 Post subject: Re: WrongClassException
PostPosted: Sun Dec 19, 2010 10:28 am 
Pro
Pro

Joined: Wed Nov 05, 2003 7:22 pm
Posts: 211
I also use a table per class hierarchy.
I've added the annotation and that solves the problem for me. However, now I see where this_.DTYPE in (x,y,z) in all my queries relating to that entity when leaving the entire clause out would have the exact same query result without the performance loss involved in performing this superfluous selection.

Is there some way to get around this issue without this? Apparently, Hibernate needs this to get all the subclasses, but from a query standpoint it doesn't make any sense and it's certainly not without significant cost.

Kind regards,

Marc


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