-->
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: Inheritance mapping with annotation returns duplicated entry
PostPosted: Mon Apr 03, 2006 3:12 am 
Newbie

Joined: Fri Apr 29, 2005 11:55 pm
Posts: 14
Location: China-Australia
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.


Top
 Profile  
 
 Post subject: Can someone help me?
PostPosted: Tue Apr 04, 2006 6:21 pm 
Newbie

Joined: Fri Apr 29, 2005 11:55 pm
Posts: 14
Location: China-Australia
Can someone help me, it's a bit urgent?


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.