|JPA Queries with Historical Session [message #819249]
||Mon, 12 March 2012 13:15
| Alfredo Osorio
Registered: March 2012
Is it possible to execute a JPQL using a HistoricalSession instead of the EclipseLink query language?|
Right now I'm forced to do queries like this:
JpaEntityManager jpaEntityManager = entityManager.unwrap(JpaEntityManager.class);
ClientSession clientSession = jpaEntityManager.getServerSession().acquireClientSession();
AsOfClause asOfClause = new AsOfClause(date);
Session historicalSession = clientSession.acquireHistoricalSession(asOfClause);
ReadAllQuery historicalQuery = new ReadAllQuery(Employee.class);
List<Employee> employees = (List<Employee>)historicalSession.executeQuery(historicalQuery);
I would like to do something like:
String jpql = "select e from Employee e";
List<Employee> employees = entityManager.createQuery(jpql, Employee.class).getResultList();
instead of using the ReadAllQuery and still be using the Historical Session.
Is it possible?
If it is not possible I would like to contribute to implement it. Can someone tell me where to start?
[Updated on: Tue, 13 March 2012 17:56]
Report message to a moderator
|Re: JPA Queries with Historical Session [message #825195 is a reply to message #819249]
||Tue, 20 March 2012 11:33
| James Sutherland
Registered: July 2009
Location: Ottawa, Canada
This is not directly possible, but you can set an asOf clause on a JPQL query using the query hint "eclipselink.history.as-of".|
To get a historical EntityManager would be more work, you could implement this is you want to give it a try. You would add an asOf() API to JpaEntityManager and EntityManagerImpl in EclipseLink. This would return an EntityManagerImpl that wrapped the HistoricalSession instead of a UnitOfWork as it normally does. This would be a read-only EntityManager, so would need to throw an error to any request for modification such as persist/merge/flush/getTransaction/etc.
It would be some work, but should not be too difficult.
James : Wiki : Book : Blog : Twitter
Powered by FUDForum
. Page generated in 0.02265 seconds