我有两个实体Person
和BlacklistInfo
,它们之间有OneToOne
关系。
Person.java
@Data
@Entity
@Immutable
@Table(name = "person_tbl")
public class Person {
@Column(name = "person_id")
@Id
private Long personId;
// ... other members
@OneToOne
@JoinColumn(name = "person_id", referencedColumnName = "person_id")
private BlacklistInfo blacklistInfo;
}
AdditionalInfo.java
@Data
@Entity
@Immutable
@Table(name = "blacklist_info_tbl")
public class BlacklistInfo {
@Id
@Column(name = "person_id")
private Long personId;
// ... other members
}
CCD_ 5的CCD_ 4可以为空。当前我想查找未列入黑名单的人员。
我可以通过以下操作之一来完成操作:
- 查询所有人并从他们中删除黑名单
- 做左联接查询,检查
BlacklistInfo
的personId
为空select p from Person p left join p.blacklistInfo where p.blacklistInfo.personId is null
问题是:Can I do the 2nd operation without explicitly mentioning left join the in query section? Can it be done by modifying entity relationship ?
我使用hibernate-5.4.12.Final
和spring-boot-2.2.x
您还想如何查询这些信息?使用JPQL/HQL来做这件事是完全可以的。