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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:46:27+00:00 2026-05-25T16:46:27+00:00

I am new to Hibernate and went through the Hibernate tutorial last week. I

  • 0

I am new to Hibernate and went through the Hibernate tutorial last week. I have a few doubts about methods save, update, saveOrUpdate and merge in the Session class. These are:

  • save method: it is used to insert the newly created object in the datastore. (Basically identifier value will be 0 for this). Like I create a new customer and call save operation, it will persist it in the datastore and generate the identifier.

    Is this correct? And if we call save on already persistent object not sure what will happen?

  • update method: it is used to update the already persistent object in the datastore.(Basically identifier value will be some non zero value for this). Like I load a new customer and call update operation after update of some field value, it will update it in datastore.

    As per my understanding it should fail with some exception because as per API update is for detached object. Is this correct? If yes, what should we call to update the object in the same session (I mean if object is not detached). Another point is: what will happen if we call update on newly created object?

  • saveOrUpdate method: it will call either of above based on unsaved-value checks (which it must be doing based on identifier zero or non zero value, right?) so if we have persistent customer object and we update last name of his and create a new account also, then saveOrUpdate will take care of it.

    Did I understand that correctly?

  • Merge method: it will act like update but here if a persistent object with the same identifier is already in the session it will update the detached object values in the persistent object and save it.

    But if there is no persistent instance currently associated with the session, this will load the persistent object from the datastore and then update the value of detached object in loaded persistent object and then update it.

    Did I also get that?

  • 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-25T16:46:27+00:00Added an answer on May 25, 2026 at 4:46 pm

    You are exactly right in all of your assessments. You get it.

    For your first question, if i recall correctly, save specifically does an insert. So calling save again will result in another row in the db.

    For your second question, update updates an object in the session. So if the object is in the session it will update. If the object is not in the session, you should call merge. I believe calling update for a detached instance will result in an exception.

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

Sidebar

Related Questions

Hi i am new to hibernate technology and i have few issues. Suppose if
im new to hibernate! i have followed the netbeans tutorial on creating a hibernate
I am new to Hibernate. I have an exception while running an Hibernate-based application.
I am new to hibernate and I am stumped. In my database I have
I'm quite new to hibernate and have stumbled on this problem, which I can't
I'm new to Hibernate and I'm struggling with problem: I have 3 tables and
im new in hibernate and JPA and i have some problems with annotations. My
I am new to Hibernate and have the following situation: class A class Course
I am complete new to Hibernate and I have a question in the following
I am quite new to hibernate. I have got the following tables: Contract ContractID

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.