Hi
I tried to implement some temporal properties on my domain objects.
I did it using a Map<Date, MyObject>, the date being the time when the value started to be the correct value. I therefor have access to the history of the different values.
My current problem is to query the object and restrict on the current value of MyObject, that is to say, the value corresponding to the max(key) in the map. I can't really find a way of doing it using the Criteria API...
In SQL, I'll be doing something like:
Code:
select *
from Demande d, demande_etat de
where d.numdemtrf=de.numdemtrf
and de.etademtrf = :TheStateIAmLookingFor
and dtetademtrf = (select max(dtetademtrf) from demande_etat de2 where de2.numdemtrf=d.numdemtrf)
Hibernate version: 3.1.3
Mapping documents:Code:
<hibernate-mapping package="model">
<class name="Demande" table="DEMANDE">
<map name="etatHistory" table="DEMANDE_ETAT" cascade="persist,merge,save-update,delete-orphan,delete-orphan">
<key column="NUMDEMTRF" />
<map-key column="DTETADEMTRF" type="date" />
<many-to-many column="ETADEMTRF" unique="true"
class="model.typesafeenum.Etat" />
</map>
</class>
</hibernate-mapping>