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

  • Home
  • SEARCH
  • 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 8136107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T10:38:50+00:00 2026-06-06T10:38:50+00:00

I’m a bit confused about how getters and setters in JPA annotated POJO classes

  • 0

I’m a bit confused about how getters and setters in JPA annotated POJO classes interact with a proposed MySQL database via Hibernate.

I understand that you can have, for example, the following:

@Entity
@Table(appliesTo = "users")
public class UserDM implements UserIF, Serializable {

  private static final long serialVersionUID = 1L;
  private long              id;
  private String            name;
  private Date              createDate;

  @Id  
  @Column(name="id")  
  @GeneratedValue(strategy=GenerationType.AUTO)
  public long getId() {
      return id;
  }

  public void setId(long id) {
    this.id = id;
  }

  public String getName() {
    return name;
  }

  public void setName(final String n) {
    name = n;
  }

  public Date getCreateDate() {
    return createDate;
  }

  public void setCreateDate(final long time) {
    createDate = new Date(time);
  }
}
  • Why is the auto ID generation strategy associated with the Getter?

  • How does that method actually auto-incremeent the ID when a new user is stored?

  • What is the order of operations? The POJO is filled via setters (or maybe a constructor?) and then the info is acquired by hibernate via getters and then stored into the db?

  • Is it a good idea to have my “getCreateDate” method return a date, or is it best to have the fields in pojos map to MySQL-friendly fields? If I wanted to get a Date object from a timestamp ms value, would the best way to do that be to use a transient mapped function?

  • 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-06T10:38:55+00:00Added an answer on June 6, 2026 at 10:38 am

    Why is the auto ID generation strategy associated with the Getter?

    This is a matter of taste, most of the time. You can put the annotations on fields or accessors (getters), depending on how you prefer, as long as it’s consistent (always on methods, or always on properties). By setting it to the property, Hibernate will use reflection to get access to the property (it’s not as bad as it sounds). By setting it to the method, Hibernate will use it instead of reflection.

    How does that method actually auto-incremeent the ID when a new user is stored?

    Not sure at which level of details you want the answer, but to keep it short:
    Auto will use the best auto-increment strategy for the database server you are using. It could be “identity” for Sybase/SQLServer, it could be “sequence” for Oracle-like or it could be “auto increment” for MySQL. Common to all those cases is the fact that Hibernate will not know the ID until the database generates it. After triggering an “insert”, Hibernate will use a standard JDBC method to access the “generated id”

    What is the order of operations? The POJO is filled via setters (or maybe a constructor?) and then the info is acquired by hibernate via getters and then stored into the db?

    Again, I don’t know which level of details you want this, but yes, that’s the order. You fill the POJO and you call the persist method on the EntityManager, passing this POJO as parameter. Hibernate will then call the getters (or access the properties) and will send this data to the database.

    Is it a good idea to have my “getCreateDate” method return a date, or is it best to have the fields in pojos map to MySQL-friendly fields? If I wanted to get a Date object from a timestamp ms value, would the best way to do that be to use a transient mapped function?

    Try to keep your application “database agnostic”. So, don’t make it “mysql friendly” if you don’t really need. In general, using a java.util.Date in a field mapped with @Temporal(TIMESTAMP) would do, but if you need more “powerful” date/time objects, like Joda-time, you can also use it (as long as you tell Hibernate how to use it).

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a reasonable size flat file database of text documents mostly saved in
I have a view passing on information from a database: def serve_article(request, id): served_article
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.