HQL:获取集合的最后一个元素 [英] HQL: get last element of collection

查看:197
本文介绍了HQL:获取集合的最后一个元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Person实体,它与Address实体(具有一些布尔属性)具有多对多关系.这种关系借助单独的表(不是实体)来表示

I have Person entity, which have many-to-many relationship with Address entity (which has some boolean property). This relationship represent with help of separate table (which is not an entity)

我需要一个查询,例如: 来自人p,其中p.addresses为空或p.addresses.getLastElement.propert为TRUE"

I need a query like: "from Person p where p.addresses is empty or p.addresses.getLastElement.propert is TRUE"

问题:

Question:

  1. 我可以在HQL问题中提取p.addresses集合的最后一个元素吗?如果是,怎么办?
  2. 如果否,我可以将多对多关系表示为实体吗?

推荐答案

我可以在HQL问题中提取p.addresses集合的最后一个元素吗? 如果是,怎么办?

Can I pull the last element of p.addresses collection in HQL question? If yes, How?

对于这个问题,您可以尝试以下方法:

For this question, you can try out the following:

from Person p where p.addresses[size(p.addresses) - 1].propert = TRUE

这不会获取collection的最后一个实体,但会检查最后一个实体的属性值&将会相应地获取Person.

This won't fetch the last entity of collection but will check the last entity's property's value & will fetch Person accordingly.

这篇关于HQL:获取集合的最后一个元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆