开发者

HQL with Null check for one-to-one relation

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 enti开发者_如何学Pythonties 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?


Ok I found the solution:

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


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)


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜