可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I have the following one-to-one relation in Hibernate (that could be null):
<one-to-one name="details" class="com.example.Details" lazy="false" cascade="all"/>
I am trying to select all entities that have non-null details with HQL:
from Entity e where e.details is not null
but this returns all entities, no matter whether details are null or not.
What would be a correct HQL then?
回答1:
Ok I found the solution:
select e from Entity e join e.details d where d is not null
回答2:
Let's suppose this one-to-one relation is part of the mapping of herpderp table, hence herpderp entity has the details property.
Do you mean the query returns those herpderp records where the herpderp.details
field is null?
Or do you mean something like this?
from Entity e where e.details.someDetailsField is not null
回答3:
You can also most likely use the elements
HQL function.
From the Expressions section of HQL 3.3 Documentation
from Cat cat where exists elements(cat.kittens)
Which should translate to your query as
Select Entity e where exists elements(e.details)