-->
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.  [ 5 posts ] 
Author Message
 Post subject: org.hibernate.WrongClassException -known methods do not help
PostPosted: Tue Jan 03, 2012 5:43 pm 
Newbie

Joined: Sun Aug 21, 2011 11:40 am
Posts: 9
Hi,
i got a error:
Code:
org.hibernate.WrongClassException: Object with id: 1221 was not of the specified subclass: model.data.OpenQuestion (loaded object was of wrong class class model.data.SingleQuestion)


Bellows is part of my code showing important associations

Code:
@Entity
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(

       name="type",
       discriminatorType=DiscriminatorType.STRING,
       length=5

)
public abstract class Question  implements Serializable{
//in this class i don't have important associations
}


Code:
@Entity
@DiscriminatorValue("Open")
public class OpenQuestion
    extends Question
{
//in this class i don't have important associations
}

Code:
@Entity
@DiscriminatorValue("Singl")
public class SingleQuestion
    extends Question
{
//in this class i don't have important associations
}

Code:
@Entity
@DiscriminatorValue("Multi")
public class MultipleQuestion
    extends Question
{
//in this class i don't have important associations
}


And bellows is other hierarchy of my class referring to the above

Code:
@Entity
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(

       name="type",
       discriminatorType=DiscriminatorType.STRING,
       length=5

)
public abstract class Answer implements Serializable {
//in this class i don't have important associations
}


Code:
@Entity
@DiscriminatorValue("Open")
public class OpenAnswer
    extends Answer
{
@ManyToOne(fetch=FetchType.LAZY,cascade={CascadeType.REFRESH, CascadeType.MERGE, CascadeType.PERSIST})
    @JoinColumn(name = "question_id")
    public OpenQuestion getQuestion() {
        return question;
    }


}


Code:
@Entity
@DiscriminatorValue("Singl")
public class SingleAnswer
    extends Answer
{
    @ManyToOne(fetch=FetchType.LAZY,cascade={CascadeType.REFRESH, CascadeType.MERGE, CascadeType.PERSIST}, optional=false)
    @JoinColumn(name = "question_id")
    public SingleQuestion getQuestion() {
        return question;
    }
}

Code:
@Entity
@DiscriminatorValue("Multi")
public class MultipleAnswer
    extends Answer
{
    @ManyToOne(fetch=FetchType.LAZY,cascade={CascadeType.REFRESH, CascadeType.MERGE, CascadeType.PERSIST}, optional=false)
    @JoinColumn(name = "question_id")
    public MultipleQuestion getQuestion() {
        return question;
    }
}


I dont have any idea how can I fix this problem. I tried: @Where clause and @DiscriminatorOptions(force=true) - i use hibernate 4.


Top
 Profile  
 
 Post subject: Re: org.hibernate.WrongClassException -known methods do not help
PostPosted: Tue Jan 03, 2012 6:45 pm 
Beginner
Beginner

Joined: Wed Nov 21, 2007 10:24 am
Posts: 25
I'd check the data in your database and make sure everything is showing the correct discriminator. You may also want to check your table structure and the queries hibernate is running against them. It seems like you have multiple types with their own properties mapped to the same column in the database (even if they are subclassed from the same type).


Top
 Profile  
 
 Post subject: Re: org.hibernate.WrongClassException -known methods do not help
PostPosted: Tue Jan 03, 2012 7:17 pm 
Newbie

Joined: Sun Aug 21, 2011 11:40 am
Posts: 9
Quote:
I'd check the data in your database and make sure everything is showing the correct discriminator. You may also want to check your table structure and the queries hibernate is running against them.

Everything is OK


Top
 Profile  
 
 Post subject: Re: org.hibernate.WrongClassException -known methods do not help
PostPosted: Wed Jan 04, 2012 11:44 am 
Newbie

Joined: Sun Aug 21, 2011 11:40 am
Posts: 9
Fortunately, is already OK :)

I change
Quote:
@ManyToOne(fetch=FetchType.LAZY,cascade={CascadeType.REFRESH, CascadeType.MERGE, CascadeType.PERSIST} /* , targetEntity = OpenQuestion.class */)
@JoinColumn(name = "question_id")
public OpenQuestion getQuestion() {
return question;
}

@ManyToOne(fetch=FetchType.LAZY,cascade={CascadeType.REFRESH, CascadeType.MERGE, CascadeType.PERSIST}, optional=false /* , targetEntity = SingleQuestion.class */)
@JoinColumn(name = "question_id")
public SingleQuestion getQuestion() {
return question;
}

@ManyToOne(fetch=FetchType.LAZY,cascade={CascadeType.REFRESH, CascadeType.MERGE, CascadeType.PERSIST}, optional=false /* , targetEntity = MultipleQuestion.class */)
@JoinColumn(name = "question_id")
public MultipleQuestion getQuestion() {
return question;
}



to
Quote:
@ManyToOne(fetch=FetchType.LAZY,cascade={CascadeType.REFRESH, CascadeType.MERGE, CascadeType.PERSIST} , targetEntity = Question.class )
@JoinColumn(name = "question_id")
public OpenQuestion getQuestion() {
return question;
}

@ManyToOne(fetch=FetchType.LAZY,cascade={CascadeType.REFRESH, CascadeType.MERGE, CascadeType.PERSIST}, optional=false , targetEntity = Question.class )
@JoinColumn(name = "question_id")
public SingleQuestion getQuestion() {
return question;
}

@ManyToOne(fetch=FetchType.LAZY,cascade={CascadeType.REFRESH, CascadeType.MERGE, CascadeType.PERSIST}, optional=false , targetEntity = Question.class )
@JoinColumn(name = "question_id")
public MultipleQuestion getQuestion() {
return question;
}


I do not know to the end why, but it's works

How do you think - something else could go wrong for this reason ? It seems to me, everything is ok.


Top
 Profile  
 
 Post subject: Re: org.hibernate.WrongClassException -known methods do not help
PostPosted: Thu Jan 05, 2012 5:53 am 
Newbie

Joined: Sun Aug 21, 2011 11:40 am
Posts: 9
Unnecessary, after change to:
Code:
targetEntity = Question.class

i got a error when i retrieve objects by criteria

Code:
org.hibernate.PropertyAccessException: IllegalArgumentException occurred while calling setter of model.data.OpenAnswer.question



so it isn't good solution


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