• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JPA Optimistic Locking Test

 
Ranch Hand
Posts: 153
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I am trying to write a simple test for Optimistic Locking





I would have expected that the entity in the DB has the name "bla" but it has "fasel".
And no OptimisticLockException has been thrown.

 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Markus Schmider wrote:I would have expected that the entity in the DB has the name "bla" but it has "fasel".
And no OptimisticLockException has been thrown.


Some questions:
- is the version number increased after the first update?
- how many SQL UPDATE statements are executed?
 
Markus Schmider
Ranch Hand
Posts: 153
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I see two updates in the log


The Version number is 2 after the test (I delete all entries before each test)

Btw I am using Wildfly 8.2
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Markus Schmider wrote:I see two updates in the log


And what about the parameters used for this query? What's the version of the entity after the first update? And what's the version of the Eintrag instance referred by eintrag2 before the update is executed?
 
Rancher
Posts: 4801
50
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's a single Transaction, so both those updates are part of the one transaction, so both apply.

It's no different to doing an UPDATE followed by another UPDATE then finally committing, directly in the database.
 
Markus Schmider
Ranch Hand
Posts: 153
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dave, you're right. Thanks



This works as expected

 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Markus Schmider wrote:This works as expected


It might be useful for other ranchers if you provided the (relevant) portion of the EintragDAO class too (as it contains the transaction configuration).
 
Markus Schmider
Ranch Hand
Posts: 153
3
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator










Because this is an EJB each method has the default TransactionAttribute Required. This means that a Tx begins with each method and ends when the method returns.
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Markus Schmider wrote:Because this is an EJB each method has the default TransactionAttribute Required. This means that a Tx begins with each method and ends when the method returns.


Thanks for coming back and sharing your solution. It might be helpful for other ranchers. Have a cow!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic