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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:31:32+00:00 2026-06-02T15:31:32+00:00

I have an entity: <class name=name.dargiri.model.Entity table=ENTITY optimistic-lock=version> <version name=version column=ver type=long /> </class

  • 0

I have an entity:

<class name="name.dargiri.model.Entity" table="ENTITY" optimistic-lock="version">
  <version name="version" column="ver" type="long" />
</class

If the Entity is saved no matter how many times, in the end of transaction Hibernate selects for the version of the object. Why? Hibernate generates this version when it stores the object, so it knows it. I found out that this method invokes this:

EntityVerifyVersionProcess#getCurrentVersion()

Hibernate generates this in logs:

Hibernate: 
    /* update
        name.dargiri.model.Entity */ update
            ENTITY 
        set
            ver=?,
            USERNAME=?,
            lucky_number=? 
        where
            id=? 
            and ver=?
Hibernate: 
    /* get version name.dargiri.model.Entity */ select
        ver 
    from
        ENTITY 
    where
        id =?

I use MySQL and Session#save().

  • 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-02T15:31:34+00:00Added an answer on June 2, 2026 at 3:31 pm

    Okay, so what I didn’t write about and what appeared to be the problem is using LockMode.OPTIMISTIC:
    session.get(Entity.class, 1L, LockMode.OPTIMISTIC);

    It appeared that this is how this lock mode works – it checks at the end of the transaction whether no one changed the version of the object so far. And this happens not while flushing, because Hibernate will anyway do the check, but by the end of the transaction, which is, I think, additional option to be more careful about overwriting data.

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

Sidebar

Related Questions

I have this class @Entity @Table(name = DB.APPL_SESSION) @AttributeOverrides({@AttributeOverride(name = id, column = @Column(name
I have the following entities: @Entity public class Owner{ @Id @Column(name = OWNER_ID) @OneToMany()
I have an entity mapped as following: @Entity @Table(name = Groups) @IdClass(value = GroupId.class)
Hi every one I have these classe @Entity @Table(name = login, uniqueConstraints={@UniqueConstraint(columnNames={username_fk})}) public class
I have the following mapping: @Entity @Table(name = Prequalifications) public class Prequalification implements Serializable
I have a parent-child relationship: @Entity @Table(name = user) public final class User {
Using JPA and Hibernate I have an entity class @Entity @Table(name = "ROLES") public
Technology: Hibernate 3.0 Suppose i have Entity class Company @Entity @Table(name=tbl_companies) public class Company
I have this entity: class Room(db.Model): name = db.StringProperty() fb_user = db.ReferenceProperty(FbUser) I have
Imagine I have an entity: public class MyObject { public string Name { get;

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.