Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7674531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:45:31+00:00 2026-05-31T16:45:31+00:00

I trying to implement the active record pattern using Java/JDBC and MySQL along with

  • 0

I trying to implement the active record pattern using Java/JDBC and MySQL along with optimistic locking for concurrency handling.

Now, I have a ‘version_number’ field for all the records in a table which is incremented after every update.

There seem to be 2 strategies for implementing this:

  1. The application when it requests the data it also stores the corresponding version number of each of the objects (i.e. record). On updating, the version number is ‘sent down’ to the data layer which is used in the UPDATE…SET…WHERE query for optimistic locking
  2. The application DOES NOT store the version number, but only some parts of the object (as opposed to an entire row of data). For optimistic locking to succeed, the data layer (active record) would need to first fetch the ‘row’ from the DB, get version number and then fire the same UPDATE…SET…WHERE query for updating the record.

In the former there is the ‘first fetch’ and then an update. In the latter case you do have a ‘first fetch’ but also a fetch right before an update.

The question is this: by design, which is the better approach? Is it okay/safe/correct to have all the data, including the version number be stored in the web application’s front-end (Javascript/HTML)? Or is it better to take a performance hit of a read before update?

Is there a ‘right way’ to implement this design? I’m not sure how current implementations of active record handle this (Ruby, Play, ActiveJDBC etc.) If I’m to implement it ‘raw’ in JDBC what’s the right design decision in this case?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T16:45:32+00:00Added an answer on May 31, 2026 at 4:45 pm

    This is neither a matter of performance nor security, the two approaches are functionally different and achieve different goals.

    With the first approach you are optimistically locking the row for the user’s entire “think time.” If User 1 loads the screen, then User 2 makes changes, User 1’s changes will fail and they will see an error that they were looking at out of date data.

    With the second approach you are only protecting against interleaving writes between competing request threads. User 1 may load a page, then User 2 makes changes, then when User 1 hits submit, their changes will go through and blow out User 2’s changes. User 1 may have made a decision based on outdate information and never know.

    It’s a matter of which behaviour is the one you want for your business rules, not one or the other being technically “correct.” they are both valid, they do different things.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Rails 3.1 and following this railscast to implement active merchant, I'm trying
All I am currently trying implement something along the lines of dim l_stuff as
trying to implement a dialog-box style behaviour using a separate div section with all
Iam trying to implement a simple JMS(traditional not using springs) code in eclipse using
Does heroku support jruby. I am trying to implement a Rails 3.2.3 app using
I am using Ruby on Rails 3.0.7 and I am trying to implement an
I am using Prism 2, trying to add four navigation buttons (First Record, Last
I'm trying to implement a switch case statement like this: switch (active.attr('class')){ case video:
I am trying to implement Superfeedr subscriptions using PubSubHubbub and Ruby on Rails. The
I am using Ruby on Rails 3 and and I am trying to implement

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.