派生查询与JPA和Spring Data的无效@OnetoOne关系

发布于 2025-02-12 20:51:35 字数 594 浏览 0 评论 0原文

我有一个entity1和entity2

@Entity
class Entity1 {

   @Id
   @Column(name = "entity_id")
   private Long entityId;

   @OneToOne(orphanRemoval = true, cascade = CascadeType.ALL, fetch = FetchType.EAGER)
   @JoinColumn(name = "entity_id")    
   private Entity2 entity2;
   ...
}

我如何得出所有具有null Entity2的entity1对象? Intellij Idea告诉我我可以使用这样的smth:

List<Entity1> findAllByEntity2IsNull()

但是那不起作用,返回空列表总是

我尝试使用相对的变体:

List<Entity1> findAllByEntity2IsNotNull()

但是该变体返回所有具有null的条目,而不是null值

I have a Entity1 and Entity2

@Entity
class Entity1 {

   @Id
   @Column(name = "entity_id")
   private Long entityId;

   @OneToOne(orphanRemoval = true, cascade = CascadeType.ALL, fetch = FetchType.EAGER)
   @JoinColumn(name = "entity_id")    
   private Entity2 entity2;
   ...
}

How can I derived query all Entity1 objects that has a null entity2?
IntelliJ Idea tell that i can use smth like that:

List<Entity1> findAllByEntity2IsNull()

But that doesn't work and return empty list always

I tried to use an opposite variant:

List<Entity1> findAllByEntity2IsNotNull()

But that variant return all entries that have null and not null values

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鹿! 2025-02-19 20:51:35

我猜,找到 all byentity2isnull会使弹簧数据混淆,因此请尝试使用名称的方法

List<Entity1> findByEntity2IsNull()

I guess, findAllByEntity2IsNull confuses Spring Data, so try using method with name

List<Entity1> findByEntity2IsNull()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文