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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:36:52+00:00 2026-05-13T05:36:52+00:00

@Entity public class Person { @Id @GeneratedValue(strategy=GenerationType.IDENTITY) private Long id; private int salary; @Version

  • 0
@Entity
public class Person {
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private Long id;

    private int salary;

    @Version
    private long version;

    // ...getters and setters
}
  1. Is it required to create setter/getter for version?
  2. When persisting this entity with Hibernate, I don’t need to set this value manually, right?
  3. What else do I need to configure in order to use optimistic concurrency checking with Spring’s hibernateTemplate.saveOrUpdate? Are all databases supported?
  4. How to unit-test this entity? In my database all my records showing version field have value of 0
  5. Will calling hibernateTemplate.saveOrUpdate increment the version value every time?
  • 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-13T05:36:52+00:00Added an answer on May 13, 2026 at 5:36 am

    I would say:

    1. set/get version is required, as you might assign the version yourself sometimes (when recreating an new instance from old data)
    2. You don’t need if you read the instance from the database. (When creating it in your code with new, it would be a different story).
    3. I see nothing else. I never had a problem with a database.
    4. Unit test don’t go the database in my opinion, so tests involving the database are called integration tests. You shouldn’t have too much of them, as they are slow, and they don’t really test your code, but more the Hibernate/Driver/Database codes … You should trust them, or just test them once, but not for all your entities.
      To see version values more than 0, read/modify/update your entity in a transaction, the version increase by one. Go out of the transaction, do it again, the value increases …
    5. The version will increase each time the database row is modified.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

mI've this entity class: @Entity public class User implements Serializable { @Id @GeneratedValue(strategy=GenerationType.AUTO) private
@Entity @Inheritance(strategy = InheritanceType.SINGLE_TABLE) public class Problem { @ManyToOne private Person person; } @Entity
@Entity public class Blobx { private String name; private BlobKey blobKey; @Id @GeneratedValue(strategy =
I have written the following code: @Entity @Table(name=person) @Inheritance(strategy=InheritanceType.JOINED) public class Person { private
A typical JPA entity looks like: @Entity public class Person { @Id private int
@Entity public class TestClass implements Serializable{ private Integer id; private Set<String> mySet; @Id @GeneratedValue
let be the following entities: @Entity public class Person { @Id long id; @ManyToOne
@Entity public class Person { @ElementCollection private List<Location> locations; [...] } @Embeddable public class
Let's say we have an entity @Entity public class Person { @Id int id;
I have an entity Person: public class Person { public virtual int Id {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.