1

I'm using following Hibernate query and getting error. Product has one To Many relationship with tweeter so type for p.tweets is "List" .

Query:

@NamedQuery(
    name="getAllProductsWithNoTweets",
    query="From Product p where p.tweets is null"
)

Error is:

Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near the keyword 'is'.

2 Answers 2

2

The query makes no sense. A OneToMany will never be null. It might be empty, but not null.

If you want to get all the products without any tweet, the query should be something like

select p from Product p where p.tweets is empty
Sign up to request clarification or add additional context in comments.

Comments

1

Since p.tweets is a collection you might want to try is empty

Another thought is that you probably have to do a left join because if there are no tweets and you are joining on the tweet table then you simply won't get that product back in the results.

select p
from Product p
    left join p.tweets t
having count(t) = 0

Comments

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.