Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Query historical data with JPA
Query historical data with JPA [message #494912] Tue, 03 November 2009 03:54 Go to next message
habakuk  is currently offline habakuk
Messages: 32
Registered: October 2009
Member
Hello EclipseLink experts!

EclipseLink has a great feature to automatically maintain the history of the data using a HistoryPolicy. This is really fantastic! Very Happy

I know it is possible to access the historic data with a HistoricalSession. But this is not helpful for people using the JPA API, which is the majority of users I guess. Confused

Is there a way to query historical data with JPA/EntityManager? Perhabs with some kind of Customizer? I have searched the Docs, but have not found a solution yet. Using a ReadAllQuery is not appropiate because this would mean that I have to duplicate all the code to have one query for the current data and one for the historical data.

Thanks for help
Habakuk

Re: Query historical data with JPA [message #494944 is a reply to message #494912] Tue, 03 November 2009 05:40 Go to previous messageGo to next message
Tom Eugelink is currently offline Tom Eugelink
Messages: 807
Registered: July 2009
Senior Member
> EclipseLink has a great feature to automatically maintain the history of
> the data using a HistoryPolicy. This is really fantastic!

You just made me a very very very happy man. I had no idea Eclipselink has such a feature! (I did post a question about this on this newsgroup some time ago.) So I was contemplating about how to bolt this on top of the BM, because Informix has no practical solution for this and using stored procedures is a disaster to maintain.

Tom
Re: Query historical data with JPA [message #495008 is a reply to message #494912] Tue, 03 November 2009 09:15 Go to previous message
habakuk  is currently offline habakuk
Messages: 32
Registered: October 2009
Member
Found the solution myself. Use a QueryHint like this:

EntityManager em = <create your entity manager>
try {
    Query query = em.createQuery( <somequery> );	
    query.setHint(QueryHints.AS_OF, "2009/11/3 11:03:12.1");
    query.setHint(QueryHints.MAINTAIN_CACHE, HintValues.FALSE);
}
    result = query.getResultList();
}finally {
    em.close();
}


Unfortunatly there seems a bug in the QueryHintHandler for the AsOf clause. The date never gets converted, only the time. I filed a bug report bug 294059 It would be great if somebody could fix this.

Thanks
Habakuk
Previous Topic:[toplink] em.merge() changes Java Identity of detached object
Next Topic:Foreign key contraints from optional bundles
Goto Forum:
  


Current Time: Sun Aug 31 04:31:55 EDT 2014

Powered by FUDForum. Page generated in 0.11454 seconds