簡體   English   中英

HQL與Null檢查一對一關系

[英]HQL with Null check for one-to-one relation

我在Hibernate中有以下一對一關系(可能為null):

<one-to-one name="details" class="com.example.Details" lazy="false" cascade="all"/>

我試圖用HQL選擇所有具有非空詳細信息的實體:

from Entity e where e.details is not null

但是這會返回所有實體,無論細節是否為null。

那么什么是正確的HQL呢?

好的我找到了解決方案:

select e from Entity e join e.details d where d is not null

您也可能最有可能使用elements HQL函數。

HQL 3.3文檔的表達式部分

from Cat cat where exists elements(cat.kittens)

哪個應該轉換為您的查詢

Select Entity e where exists elements(e.details)

讓我們假設這種一對一的關系是herpderp表映射的一部分,因此herpderp實體具有details屬性。

你的意思是查詢返回herpderp.details字段為空的那些herpderp記錄?

或者你的意思是這樣的?

from Entity e where e.details.someDetailsField is not null

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM