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.