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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:01:21+00:00 2026-05-23T04:01:21+00:00

Under what circumstances would it be appropriate to explicitly exclude optimistic locking from a

  • 0

Under what circumstances would it be appropriate to explicitly exclude optimistic locking from a @OneToMany relationship via Hibernate?

I have been reading a post on Hibernate which basically says any updates to child entities will cause an optimistic lock on parent entity, which is typically unneeded. The key word here is typically… can anyone explain more precisely when you would or would not need optimistic locking on a relationship like this?

Here is the code example given to demonstrate optimistic lock exclusion:

// Bars - these are specifically excluded from optimist lock
// for the object, since we don't want to obtain optimistic
// lock when we add a new bar
@OptimisticLock(excluded = true)
@OneToMany
@JoinColumn(name = "FOO_ID", nullable = false, updatable = false)
private List<FooBar> bars = new LinkedList<FooBar>();
  • 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-23T04:01:22+00:00Added an answer on May 23, 2026 at 4:01 am

    Basically, you need optimistic locking for one-to-many relationships when parent logically “owns” its children, in other words, when parent and children are modified at once as a whole. An Order consisting of OrderLines, which are presented to the user at the same form, can be an example of this kind of relationship.

    Otherwise, when children should be modified individually, they should be excluded from optimistic locking. Topic with Posts can be an example of this case.

    Technically speaking, this question is related to directionality of relationships. The purpose of optimistic locking is to prevent lost modifications, so that you need to enable it for one-to-many relationships when lost modifications are possible. This happens when parent is the owning side of relationship, in other words, when one-to-many relationships are unidirectional (note that it’s a natural choice to model relationships such as Order–OrderLine).

    In the case of bidirectional one-to-many relationships a “many” side is the owning side of the relationship, so that modifications of relationship at the “one” side doesn’t affect the database, therefore they can’t be lost.

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

Sidebar

Related Questions

Under what circumstances would this or would this not be safe? I have a
Just wondering under what circumstances would you prefer to generate a proxy from a
I have a service application written in C# and under certain circumstances, I would
Under what circumstances would you use MicrosoftAjax over jQuery in an ASP.NET MVC application?
Under what circumstances (if any) would you allow an application to change its underlying
How would you represent a temporal many-to-many relation in SQL? Under non-temporal circumstances one
Under what circumstances is an enum more appropriate than, for example, a Collection that
Under what circumstances would java.util.zip.ZipFile.close() throw an IOException? Its method signature indicates that it
Which is a better practice, generally speaking, and why? Under what circumstances would you
I was wondering under what circumstances you would use a rope over another STL

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.