我正在尝试使用hibernate从我的数据库中检索数据...我有一个使用左连接连接两个表(所有字段是一对一)的查询。我需要知道如何使用hibernate和注释来处理这个问题。我创建了两个映射到表的类,我试图弄清楚如何使用连接... Hibernate文档令人困惑......
//一个班级
@Entity
@Table(name = "Class1")
public class Class1{
@Id
@Column(name = "INITIAL")
private String initial;
@Column(name = "NUMBER")
private Integer number;
...
// twoclass
@Entity
@Table(name = "Class2")
public class Class2{
@Column(name = "STATE")
private String state;
@Id
@Column(name = "NUMBER")
private Integer number
...
答案 0 :(得分: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;
}