0

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

1 Answer 1

1

If your HistoryMap implements java.util.Map (and respects the interface's contracts) then you can use Criteria API. If not, I don't think it will work with HQL (and with Criteria API). In that case, using native SQL is your best bet. You can make a native query who's result is marshaleld to a specific Hibernate Bean:

http://docs.jboss.org/hibernate/core/3.3/reference/en/html/querysql.html#d0e13696

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.