HQL: get last element of collection

纵饮孤独 提交于 2019-12-08 01:14:44

问题


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)

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

Question:

  1. Can I pull the last element of p.addresses collection in HQL question? If yes, How?
  2. If no, can I represent many-to-many relationship as entity?

回答1:


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

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



来源:https://stackoverflow.com/questions/19681268/hql-get-last-element-of-collection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!