jsight
jsight

Reputation: 28419

Hibernate: Retrieve rows that are not joined

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?

Upvotes: 0

Views: 215

Answers (2)

digitaljoel
digitaljoel

Reputation: 26574

assuming email can have only one body:

from Email e where e.body is null

Upvotes: 1

Kees de Kooter
Kees de Kooter

Reputation: 7195

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

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

Upvotes: 1

Related Questions