不知道为什么需要多个选择,这里是类
DrivingLicense.java
@Entity
@Table(name = "DRIVING_LICENSE")
public class DrivingLicense {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "LICENSE_NUMBER")
private int licenseNumber;
@Column(name = "DATE_OF_ISSUE")
private Date dateOfIssue;
@OneToOne(mappedBy = "drivingLicense", cascade = CascadeType.ALL)
private Person person;
}
Person.java
@Entity
@Table(name = "PERSON")
public class Person {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "PERSON_ID")
private int personId;
@Column(name = "PERSON_NAME", nullable = false, length = 30)
private String personName;
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "D_LICENSE_NUMBER")
private DrivingLicense drivingLicense;
}
TestClass
TypedQuery<Person> query = entityManager.createQuery("from Person p", Person.class);
query.getResultList();
此处query.getResultList
正在生成以下sqls
Hibernate: select person0_.PERSON_ID as PERSON_ID1_1_, person0_.D_LICENSE_NUMBER as D_LICENSE_NUMBER3_1_, person0_.PERSON_NAME as PERSON_NAME2_1_ from PERSON person0_
Hibernate: select drivinglic0_.LICENSE_NUMBER as LICENSE_NUMBER1_0_0_, drivinglic0_.DATE_OF_ISSUE as DATE_OF_ISSUE2_0_0_, person1_.PERSON_ID as PERSON_ID1_1_1_, person1_.D_LICENSE_NUMBER as D_LICENSE_NUMBER3_1_1_, person1_.PERSON_NAME as PERSON_NAME2_1_1_ from DRIVING_LICENSE drivinglic0_ left outer join PERSON person1_ on drivinglic0_.LICENSE_NUMBER=person1_.D_LICENSE_NUMBER where drivinglic0_.LICENSE_NUMBER=?
Hibernate: select person0_.PERSON_ID as PERSON_ID1_1_1_, person0_.D_LICENSE_NUMBER as D_LICENSE_NUMBER3_1_1_, person0_.PERSON_NAME as PERSON_NAME2_1_1_, drivinglic1_.LICENSE_NUMBER as LICENSE_NUMBER1_0_0_, drivinglic1_.DATE_OF_ISSUE as DATE_OF_ISSUE2_0_0_ from PERSON person0_ left outer join DRIVING_LICENSE drivinglic1_ on person0_.D_LICENSE_NUMBER=drivinglic1_.LICENSE_NUMBER where person0_.D_LICENSE_NUMBER=?
为什么需要2个选择我不知道。在这两个表格中只有一条记录。