我尝试使用内部选择,但只得到异常“HibernateException:命名查询中的错误”
两个 JPA 实体:
public class A implements Serializable {
@Id
@Column(nullable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
}
public class B implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@JoinColumn(name = "FK_A_ID", nullable = true)
@ManyToOne
private A a;
}
此查询导致异常:
SELECT a FROM A a WHERE a.id NOT IN (SELECT b.a.id FROM B b)
但这也不例外:
SELECT a FROM A a WHERE a.id NOT IN (1, 2, 3)
知道有什么问题吗?非常感谢...