-->
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.  [ 1 post ] 
Author Message
 Post subject: Abstract class Inheritance not working
PostPosted: Thu Jul 23, 2015 2:32 am 
Newbie

Joined: Thu Jul 23, 2015 2:12 am
Posts: 1
I have two abstract class and two concrete class for both the abstract class. Question class abstraction is working as expected but choice is not working as expected and throwing below error:

javax.persistence.PersistenceException: org.hibernate.WrongClassException: Object with id: 644b7a9d-4d92-4120-af41-8067a321bd1a was not of the specified subclass: com.xyz.model.Choice (Discriminator: RCO)

Here is how my database records looks like:
Question Table:
dtype: uuid
RNQ : "cc8aa5f7-a8ff-42b5-9079-ce099368b4fa"
CEQ : "b3a7e603-6e79-46ce-bb4f-3a9a152e0407"

Choice Table:
dtype: uuid : question_uuid
RCO : "644b7a9d-4d92-4120-af41-8067a321bd1a" : "cc8aa5f7-a8ff-42b5-9079-ce099368b4fa"
CHO : "b20dce82-3b9d-4841-808f-bfe98edeade6" : "b3a7e603-6e79-46ce-bb4f-3a9a152e0407"

Notice choice question is working with correct choices while ranking question is throwing the above error and does not associate rankchoice object instead it's trying to associate choice object.

This is how objects looks like:

@XmlRootElement
@XmlSeeAlso({Choice.class, RankChoice.class})
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(discriminatorType = DiscriminatorType.STRING, length = 3)
@DiscriminatorValue("CCO")
@Table(name = "choice")
public abstract class AbstractChoice {
---some fields
---some fields
}

Concrete class 1:

@Entity
@DiscriminatorValue("CHO")
public class Choice extends AbstractChoice{
private ChoiceQuestion question;
}

Concrete class 2:
@Entity
@DiscriminatorValue("RCO")
public class RankChoice extends AbstractChoice{

private RankQuestion question;
}

Another abstract class

@XmlRootElement
@XmlSeeAlso({ChoiceQuestion.class, RankQuestion.class})
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(discriminatorType = DiscriminatorType.STRING, length = 3)
@DiscriminatorValue("QES")
@Table(name = "question")
public abstract class Question {
---Some fields
}

Concrete class 1:

@XmlRootElement
@Entity
@DiscriminatorValue("CEQ")
public class ChoiceQuestion extends Question {
private List<Choice> choices;

@XmlElementRefs({
@XmlElementRef(type = Choice.class)
})
@OneToMany(fetch = FetchType.LAZY, cascade = {CascadeType.ALL})
@OrderColumn(name="choice_index")
@JoinColumn(name = "question_uuid")
public List<Choice> getChoices() {
return choices;
}
}

Concrete class 2:

@XmlRootElement
@Entity
@DiscriminatorValue("RNQ")
public class RankQuestion extends Question {
private List<RankChoice> choices;

@XmlElementRefs({
@XmlElementRef(type = RankChoice.class)

})
@OneToMany(fetch = FetchType.LAZY, cascade = {CascadeType.ALL})
@OrderColumn(name="choice_index")
@JoinColumn(name = "question_uuid")
public List<RankChoice> getChoices() {
return choices;
}
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.