This is my situation: I have a document that can have only one of 13 states. The state of a document changes in time and the the date of that change of state is needed. I have these tables:
Documents: id, name
DocumentState: id, idDocument, idState, date
States: id, name
I need to get all documents which actual state (state with max date) is 1 or 12.
I tried to make this with a DetachedCriteria but it generates a nested query that is pretty bad for performance, so, I'm looking for a way force hibernate to use a temporary table instead.
Thanks in advance