简体   繁体   中英

derived querying a nullable @OneToOne relationship with JPA and Spring Data

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

我猜,发现All ByEntity2IsNull 混淆了 Spring Data,所以尝试使用带有名称的方法

List<Entity1> findByEntity2IsNull()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM