views:

109

answers:

2

I have two tables joined together with entities like this (entities anonymized, and trimmed of irrelevant properties):

Email - Email_ID - Title - Body (hibernate uses a Body_ID field here)

Body - Body_ID - Body_Text

I'd like to retrieve all Email entries that do not have an associated Body row (ie, Body_ID is null). What HQL would do this?

+1  A: 

Assuming you have an Email object with a @OneToOne or @ManyToOne to Body:

select e from Email as e where e.body is null

Kees de Kooter
This returns 0 results... I assume because there is no e.body at all (since the body row doesn't exist at all).
jsight
Oops, I completely misread this... that does work.
jsight
+1  A: 

assuming email can have only one body:

from Email e where e.body is null
digitaljoel