2

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?

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

2 Comments

Here I have used one to one mapping. It also considered as a collection?
Include essential parts of the linked article in your answer. Just in case the java2s goes offline.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.