Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Recommended Practise: Consistent Timestamp for Unit of Work(How do you achieve a consistent timestamp ()
Recommended Practise: Consistent Timestamp for Unit of Work [message #805211] Thu, 23 February 2012 13:49 Go to next message
Marvin Toll is currently offline Marvin TollFriend
Messages: 34
Registered: July 2009
Member
/** The time the row was last updated. */
@Version
@Column(insertable = true, updatable = true, unique = false, name = "UPDATE_TIME", nullable = true, columnDefinition = "timestamp")
protected Timestamp updateTime;")
protected Timestamp updateTime;[/font][/font]

---------------
In the following unit test our CREATE_TIME is set consistently by our framework code, however - the UPDATE_TIME requires four trips to the database and it is unique for each instance.

Question: How can we ensure that a consistent @Version timestamp is used for all instances within a unit of work?
---------------
*** Begin Transaction ***; thread=http-8080-1; method=persistNonCascadedCreateUpdate

[EL Fine]: 2012-02-22 11:35:43.041--ClientSession(1801630204)--Connection(887781807)--Thread(Thread[http-8080-1,5,main])--SELECT CURRENT_TIMESTAMP()
[EL Fine]: 2012-02-22 11:35:43.042--ClientSession(1801630204)--Connection(887781807)--Thread(Thread[http-8080-1,5,main])--INSERT INTO ADDRESS (UUID_KEY, ADDRESS_LINE1_TXT, ADDRESS_LINE2_TXT, ADDRESS_LINE3_TXT, CITY_NM, COUNTRY_CD, CREATE_TIME, CREATE_USER, STATE_CD, UPDATE_TIME, UPDATE_USER, ZIP_CD) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
[EL Fine]: 2012-02-22 11:35:43.042--ClientSession(1801630204)--Connection(887781807)--Thread(Thread[http-8080-1,5,main])-- bind => [[B@62864c36, ABC1, null, null, XYZ1, USA, 2012-02-22 11:35:43.037, NotificationBFIT, CA, 2012-02-22 11:35:43.041, NotificationBFIT, 94111]
[EL Fine]: 2012-02-22 11:35:43.043--ClientSession(1801630204)--Connection(887781807)--Thread(Thread[http-8080-1,5,main])--SELECT CURRENT_TIMESTAMP()
[EL Fine]: 2012-02-22 11:35:43.044--ClientSession(1801630204)--Connection(887781807)--Thread(Thread[http-8080-1,5,main])--INSERT INTO DEBT_TYPE (UUID_KEY, DEBT_TYPE_CD, CREATE_TIME, CREATE_USER, DEBT_TYPE_DESC, DEBT_TYPE_PRIORITY_CD, UPDATE_TIME, UPDATE_USER) VALUES (?, ?, ?, ?, ?, ?, ?, ?)
[EL Fine]: 2012-02-22 11:35:43.045--ClientSession(1801630204)--Connection(887781807)--Thread(Thread[http-8080-1,5,main])-- bind => [[B@5ef59fc2, 01, 2012-02-22 11:35:43.037, NotificationBFIT, null, 1, 2012-02-22 11:35:43.041, NotificationBFIT]
[EL Fine]: 2012-02-22 11:35:43.045--ClientSession(1801630204)--Connection(887781807)--Thread(Thread[http-8080-1,5,main])--SELECT CURRENT_TIMESTAMP()
[EL Fine]: 2012-02-22 11:35:43.046--ClientSession(1801630204)--Connection(887781807)--Thread(Thread[http-8080-1,5,main])--INSERT INTO DEBT (UUID_KEY, DEBT_AGENCY_ACCT_ID, CREATE_TIME, CREATE_USER, DEBT_CURRENT_BALANCE_AMT, DEBT_DELINQUENCY_TS, DEBT_STAT_CD, UPDATE_TIME, UPDATE_USER, CR_AGENCY_SITE_UUID_KEY_FK, DEBT_TYPE_UUID_KEY_FK) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
[EL Fine]: 2012-02-22 11:35:43.047--ClientSession(1801630204)--Connection(887781807)--Thread(Thread[http-8080-1,5,main])-- bind => [[B@4fcbaa42, DebtA, 2012-02-22 11:35:43.037, NotificationBFIT, 200.00, 2007-05-23 01:01:01.999, , 2012-02-22 11:35:43.041, NotificationBFIT, [B@5c571db0, [B@5ef59fc2]
[EL Fine]: 2012-02-22 11:35:43.049--ClientSession(1801630204)--Connection(887781807)--Thread(Thread[http-8080-1,5,main])--SELECT CURRENT_TIMESTAMP()
[EL Fine]: 2012-02-22 11:35:43.049--ClientSession(1801630204)--Connection(887781807)--Thread(Thread[http-8080-1,5,main])--INSERT INTO DEBTOR (UUID_KEY, CREATE_TIME, CREATE_USER, DEBTOR_FIRST_NM, DEBTOR_LAST_NM, DEBTOR_STAT_CD, DEBTOR_TIN_NR, DEBTOR_TYPE_CD, DEBTOR_CONTROL_NM, UPDATE_TIME, UPDATE_USER, DEBT_UUID_KEY_FK, ADDRESS_UUID_KEY_FK) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
[EL Fine]: 2012-02-22 11:35:43.05--ClientSession(1801630204)--Connection(887781807)--Thread(Thread[http-8080-1,5,main])-- bind => [[B@d1e0abe, 2012-02-22 11:35:43.037, NotificationBFIT, null, Lee, , 111222333, I, null, 2012-02-22 11:35:43.041, NotificationBFIT, [B@4fcbaa42, [B@62864c36]

*** Commit [create=2012-02-22 11:35:43.037]; milliseconds = 14; instances=4; thread=http-8080-1; user id=NotificationBFIT


Marvin Toll
CTO, Pattern Enabled Development
http://pedCentral.com
Re: Recommended Practise: Consistent Timestamp for Unit of Work [message #808377 is a reply to message #805211] Mon, 27 February 2012 18:15 Go to previous message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

When you use @Version locking the lock value is maintained by EclipseLink, and it defaults to getting the timestamp from the database. You can also configure it to use the local timestamp from Java using a DescriptorCustomizer, but the timestamp value will still not be consistent for the transaction. Please log a bug (or vote for the existing one) to have the timestamp be consistent for the duration of a transaction.

If you want to set the value yourself, then you should be able to just use field locking. Use,
@OptimisticLocking(type=SELECTED_COLUMNS, selectedColumns=Column(name="UPDATE_TIME"))

and remove the @Version


James : Wiki : Book : Blog : Twitter
Previous Topic:Detached Instance Following (read-only) Query
Next Topic:Native Query using function not finding primary key
Goto Forum:
  


Current Time: Fri Apr 26 05:02:32 GMT 2024

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

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

Back to the top