I have a hibernate mapping with custom collection types in it.
java:
class Policy {
...
private HistoryMap<Date, PolicyStatus> statusHistory;
...
}
hbm.xml:
<map name="statusHistory" inverse="true" table="tbl_policy_in_time" order-by="PolIt_ValidFrom desc"
collection-type="be.pensionarchitects.admindb.infrastructure.hibernate.HistoryMapType">
...
</map>
HistoryMapType is an implementation of interface HistoryMap and implements UserCollectionType.
This map has a method getCurrent() which returns the current PolicyStatus.
Now I need to do a query to get all Policy objects having a specific PolicyStatus as current one.
Something like:
Criteria crit = getSession().createCriteria(Policy.class)
.createAlias("statusHistory.current", "status")
.add(Restrictions.or(
Restrictions.eq("status.code", "active"),
Restrictions.eq("status.code", "sleeper")));
I understand this doesn't work as "current" isn't an association mapping. How i should I solve this? I have read that I should use HQL instead, but have no idea how and if it's even possible.
Any pointers are appreciated!
Thanks