-->
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.  [ 2 posts ] 
Author Message
 Post subject: Annotation mapping inheritance exception
PostPosted: Mon Jul 13, 2009 6:34 am 
Newbie

Joined: Mon Jul 13, 2009 6:22 am
Posts: 2
Hi everyone;
I'm working with hibernate mapping inheritance and im getting this exception when I try to retrieve a GarageSpot class.
the hibernate generated the right SQL script its selecting from the GarageSpot table and joining it with the Spot table all work fine but the object i retrieve its from type Spot I tried to add the polymorphism annotaion but didnt work too

org.hibernate.WrongClassException: Object with id: 1007 was not of the specified subclass: com.data.GarageSpot (loaded object was of wrong class class com.data.Spot)

the classes look like

---------- Parent Table object --------------------
@Entity
@Table(name = "spot", uniqueConstraints = {})
@Inheritance(strategy = InheritanceType.JOINED)
@org.hibernate.annotations.ForceDiscriminator
@DiscriminatorColumn(name="type")
//@org.hibernate.annotations.Entity(polymorphism = PolymorphismType.EXPLICIT)
public class Spot extends BaseEntity implements Dictionary, Hintable
{

-------------- Child table object -----------------------
@Table(name = "garagespot", uniqueConstraints = {})
@DiscriminatorValue("0")
@PrimaryKeyJoinColumn(name="id")
//@org.hibernate.annotations.Entity(polymorphism = PolymorphismType.EXPLICIT)
public class GarageSpot extends Spot
{


P.S the Discriminator field is integer

thanks in advance


Top
 Profile  
 
 Post subject: Re: Annotation mapping inheritance exception
PostPosted: Wed Jul 15, 2009 11:55 am 
Newbie

Joined: Mon Jul 13, 2009 6:22 am
Posts: 2
I've found that the code that should return the GarageSpot (child class) will CORRECTLY return a GarageSpot, if I have not returned that same object as a Spot (parent object) earlier in the session.

Example 1:
I select all spots (garage and other) into a list (uses HQL)
I pick one of them and attempt to load it into a GarageSpot
Hibernate returns a Spot class instead of a GarageSpot, though the query that it ran joined in the GarageSpot table

Example 2:
I do not select all spots, but instead just load a particular GarageSpot
Hibernate returns a GarageSpot, as expected.

The problem seems to be that the Spot Entity was cached, though I have tried to turn off all caching. So what I'm trying to do here is to empty the cache so the new search wont take the old cached objects... how can i disable the cache on hibernate

Is there some other reason I would get these results?


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