问题
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:
- Can I pull the last element of p.addresses collection in HQL question? If yes, How?
- 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