0

我正在尝试使用休眠从我的数据库中检索数据...我有一个查询,它使用左连接连接两个表(所有字段都是一对一的)。我需要知道如何使用休眠和注释来处理这个问题。我创建了两个映射到表的类,我试图弄清楚如何使用连接......Hibernate 文档令人困惑......

//一个类

@Entity
@Table(name = "Class1")
public class Class1{

 @Id
 @Column(name = "INITIAL")
 private String initial;

  @Column(name = "NUMBER")
  private Integer number;

...

//双类

@Entity
@Table(name = "Class2")
public class Class2{

 @Column(name = "STATE")
 private String state;

  @Id   
  @Column(name = "NUMBER")
  private Integer number

...

4

1 回答 1

2
@Entity
@Table(name = "Class1")
public class Class1 {
   @Id
   @Column(name = "INITIAL")
   private String initial;

   @Column(name = "NUMBER")
   private Integer number;  
}


@Entity
@Table(name = "Class2")
public class Class2 {
   @Id
   @Column(name = "STATE")
   private String state;

   @Column(name = "NUMBER")
   private Integer number

   @OneToOne
   @JoinColumn(name = "columnWithClass1id")
   private Class1 class1;
}
于 2012-05-22T14:26:17.930 回答