Anuradha
Anuradha

Reputation: 580

Spring Boot JPA Query with is empty and is null key words

I'm using spring boot version 2.0.3.RELEASE and spring data jpa version 2.0.8.RELEASE. I have two tables TableA, TableB and they are one to one mapped.

TableA

@Entity
@Table(name = "table_a")
public class TableA {

     @Id
     @Column(name = "id")
     private Long id;

     @OneToOne(mappedBy = "table_b", cascade = CascadeType.ALL)
     private TableB tableB;
}

TableB

@Entity
@Table(name = "table_b")
public class TableB {

     @Id
     @Column(name = "id")
     private Long id;

     @OneToOne
     @JoinColumn(name = "id")
     private TableA tableA;
}

I need to get TableA values when the Mapped TableB is not existed. I wrote below query in TableA Jpa Repository.

@Query(value = "select a from TableA a where a.tableB is null and a.id=?1")
TableA findTableAValues(Long id);

But it doesn't give the expected result. If I replaced the is null with the is empty key word, query gives the expected result. Please anyone can explain why this kind of thing is happened?

Upvotes: 2

Views: 8700

Answers (1)

toto
toto

Reputation: 709

The IS EMPTY operator is the logical equivalent of IS NULL, but for collections.

You can visit this link for more details and examples http://www.java2s.com/Tutorials/Java/JPA/4070__JPA_Query_Is_Empty.htm

Upvotes: 3

Related Questions