-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Temporal Properties / Queries on Map keys
PostPosted: Thu Aug 07, 2008 5:10 am 
Beginner
Beginner

Joined: Mon Sep 26, 2005 8:22 am
Posts: 24
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>



Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 07, 2008 7:32 am 
Beginner
Beginner

Joined: Mon Sep 26, 2005 8:22 am
Posts: 24
ok...

some white magic here:
Code:
session
.createSQLQuery("select * "
+"from Demande d, demande_etat de "
+"where d.numdemtrf=de.numdemtrf "
+"and de.etademtrf = 'VAL' "
+"and dtetademtrf = (select max(dtetademtrf) from demande_trafic_etat de2 where de2.numdemtrf=d.numdemtrf)")
.addEntity(Demande.class)
.list()


Tada!

nobody for a better solution?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 08, 2008 3:43 am 
Beginner
Beginner

Joined: Mon Sep 26, 2005 8:22 am
Posts: 24
a little up, FTW


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 11, 2008 4:20 am 
Beginner
Beginner

Joined: Mon Sep 26, 2005 8:22 am
Posts: 24
last try...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.