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 8890527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:31:23+00:00 2026-06-14T22:31:23+00:00

With JPA, we can use manually OPTIMISTIC or PESSIMISTIC locking to handle entity changes

  • 0

With JPA, we can use manually OPTIMISTIC or PESSIMISTIC locking to handle entity changes in transactions.

I wonder how JPA handles locking if we don’t specify one of these 2 modes ?
No locking mode is used?

If we don’t define an explicit locking mode, can the database integrity be lost?

Thanks

  • 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-06-14T22:31:24+00:00Added an answer on June 14, 2026 at 10:31 pm

    I’ve scanned through section 3.4.4 Lock Modes of the Java Persistence API 2.0 Final Release specification and while I couldn’t find anything specific (it doesn’t state that this is the default or anything like that) there is a footnote which says the following.

    The lock mode type NONE may be specified as a value of lock mode
    arguments and also provides a default value for annotations.

    The section is about the kinds of LockModeType values available and their usages and describes which methods takes an argument of this kind and whatnot.

    So, as it said LockModeType.NONE is default for annotations (JPA, annotations left and right) I guess when you use EntityManager.find(Class, Object) the default LockModeType is used.

    There are some other, subtle, hints to reinforce this. Section 3.1.1 EntityManager interface.

    The find method (provided it is invoked without a lock or invoked with
    LockModeType.NONE) and the getReference method are not required to be
    invoked within a transaction context.

    It makes sense. For example if you use MySQL as your database and your database engine of choice is InnoDB then (by default) your tables will use REPEATABLE READ, if you use some other RDBMS or other database engines this could change.

    Right now I’m not exactly sure that isolation levels has anything to do with JPA lock modes (although it seems that way), but my point is that different database systems differ so JPA can’t decide for you (at least according to the specification) what lock mode to use by default, so it’ll use LockModeType.NONE if you don’t instruct it otherwise.

    I’ve also found an article regarding isolation levels and lock modes, you might want to read it.

    Oh, and to answer your last question.

    If we don’t define an explicit locking mode, can the database
    integrity be lost?

    It depends, but if you have concurrent transactions then the answer is probably yes.

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

Sidebar

Related Questions

Is there any way I can use JPA or hibernate annotations to specify the
I annotated a bunch of POJO's so JPA can use them to create tables
I have a composite primary key for my object.How can i use a jpa
Is there a way where we can use batch inserts using JPA EntityManager. I
Does anyone have an idea how I can use Spring Data JPA and use
I'm trying to wire up Spring Data JPA objects manually so that I can
If we use JPA/Hibernate in a project, Is there any advantage that we can
Can I use JPA 2.0(e.g EclipseLink) with Google App Engine?
I have the following question about JPA: Can I save the order of the
I am developing a system with Java EE and JPA where users can make

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.