问题描述
我有两个实体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
}
BlacklistInfo
的 Person
可以为空。目前我想找到未列入黑名单的人。
我可以通过以下操作之一来进行操作:
- 查询所有人员并从其中删除黑名单
- 执行左联接查询并检查
personId
中的BlacklistInfo
是否为空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做到这一点完全没问题。