I'm doing an inheritance mapping using @Inheritance(strategy = InheritanceType.JOINED) annotation, but when I try to retrieve a list of super class, I got duplicated entries. Here's the code
Code:
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@Table(name = "interview")
public class Interview implements Serializable{
private Integer interviewId;
private Firm firm;
@Id @GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "interview_id")
public Integer getInterviewId() {
return interviewId;
}
public void setInterviewId(Integer interviewId) {
this.interviewId = interviewId;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "firm_id")
public Firm getFirm() {
return firm;
}
public void setFirm(Firm firm) {
this.firm = firm;
}
}
@Entity
@Table(name = "suncorp_interview")
public class SuncorpInterview extends Interview {
private String investigatorName;
@Column(name = "investigator_name")
public String getInvestigatorName() {
return investigatorName;
}
public void setInvestigatorName(String investigatorName) {
this.investigatorName = investigatorName;
}
}
I have a
interview table, and
suncorp_interview table has a interview_id column, with is the primary key and the additional investigator_name field.
When I try to retrieve a list of Interview using
Code:
List list = session.createCriteria(Interview.class).list();
It all went fine, however, when I did this:
Code:
List list = session.createCriteria(Interview.class).setFetchMode("firm", FetchMode.JOIN).list();
I got a list which is twice as long as the number of entries in db, there are two copies of each record in the returned list, what's wrong with that?
Also, I try to replace the
FetchMode.JOIN with
FetchMode.SELECT, after I did that, Hibernate didn't even fetch the firm field.
Is my mapping and table stracture alll right? What's the problem?
I uses the lastest version of Hibernate and Hibernate Annotation.