Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » fixed timestamp for start/end values for historical data
fixed timestamp for start/end values for historical data [message #713591] Mon, 08 August 2011 16:15 Go to next message
Stefan Palme is currently offline Stefan PalmeFriend
Messages: 8
Registered: August 2011
Junior Member
Hi again,

here I am again with another problem. I use EclipseLink-2.2.0 in a JPA environment, and I have configured EclipseLink to track historical data using dedicated history tables (this has been done by configuring HistoryPolicies in the SessionCustomizer).

Our application creates some very big database transactions ("big" in the sense of a lot of modified data, involving a lot of tables and database records). For most of the modified data we have configured a HistoryPolicy. Since commiting such a big transaction takes a "long" time (sometimes around 2-3 seconds), the resulting row_start/row_end values in the history tables will not be absolutely equal to each other, because EclipseLink by default uses System.currentTimeMillis() to get the timestamp for each newly created history record.

The fact of non-matching row_start/row_end values in the history tables is annoying for us, because so we can not fetch the historical state of a given point in time which reflects the state either exactly BEFORE the transaction or AFTER the transaction.

I already modified the HistoryPolicy to HistoryPolicy.setShouldUseDatabaseTime(true), and now it really calls "SELECT NOW()" every time to calculate the row_start/row_end values for the history tables.

Unfortunately, the SQL standard does not enforce NOW() to return always the same value during one transaction, so in the end all the history records created in one single transaction still have row_start/row_end times which differ slightly (unfortunately we use MySQL - the NOW() function of PostgreSQL really returns always the same value in a single transaction).

So now the question: is there a way to give EclipseLink another "source of time" to be used for the row_start/row_end values? I think about something like the following pseudo-code:

EntityManager em=...;
Date now=new Date();
// ... create and modify a lot of entites resp. database records here
em.setTimestampForHistoryTables(now);
em.commit();

So even if the commit() takes a lot of time and has to create a lot of history records, all the history records will use the SAME timestamp for their row_start/row_end values...

Thanks in advance
-stefan-
Re: fixed timestamp for start/end values for historical data [message #714816 is a reply to message #713591] Thu, 11 August 2011 14:56 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

I agree that the time should only be computed once per transaction, not once per object. Especially when the database time is used, as multiple queries is not desirable.

Please log an enhancement for this request.

If you wish to investigate it, the fix should not be too difficult, when the HistoryPolicy assigns the time, just store it in the UnitOfWork for the duration of the transaction.


James : Wiki : Book : Blog : Twitter
Re: fixed timestamp for start/end values for historical data [message #886678 is a reply to message #714816] Fri, 15 June 2012 12:21 Go to previous messageGo to next message
Dieter Hubau is currently offline Dieter HubauFriend
Messages: 2
Registered: June 2012
Junior Member
Sorry to resurrect this thread, but anything news on this? We're not getting this to work.

When we try to override the getCurrentTime method of the HistoryPolicy, we can't seem to acquire the same UnitOfWork, since we're getting a new UnitOfWork FOR EACH object. We want to store the same date in the history tables for ALL objects in the same object graph.

Any suggestions?

Kind regards,
Dieter
Re: fixed timestamp for start/end values for historical data [message #889748 is a reply to message #886678] Tue, 19 June 2012 14:32 Go to previous message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

Do not acquire a UnitOfWork, the Session should be a UnitOfWork.


James : Wiki : Book : Blog : Twitter
Previous Topic:HistoryPolicy OneToOneMapping StackOverflowError
Next Topic:Logging sql with logback
Goto Forum:
  


Current Time: Thu Apr 25 07:47:55 GMT 2024

Powered by FUDForum. Page generated in 0.03271 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top