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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:27:13+00:00 2026-05-28T18:27:13+00:00

lets’s say I have: // all objects have valid mapping to database public class

  • 0

lets’s say I have:

// all objects have valid mapping to database
public class A {
   private int id;
   private String name;
   private List<B> chidlren1;
   private List<C> children2;
}

in my controller’s update method i have to update a specific object, but new values for it I store in session variable like another A object.

So the question is what valid way to update that specific object from another object?
Is the next code valid?

A old = dao.get(id);
A temp = getFromSession();

old.Name = temp.Name;
old.Children1 = temp.Children1;
old.Children2 = temp.Children2;
dao.update(old);

And another question – if previoud method is right, will hibernate first delete all records from chidlren’s tables and add a new ones or it can automatically update/insert new records and remove the deleted ones?

Thank you

UPD#1: Let’s say chidlren collections of temp are different from children collections of old?

  • 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-28T18:27:15+00:00Added an answer on May 28, 2026 at 6:27 pm

    If the ids are set properly on your child entity collections of type A and B and you have specified cascade=MERGE on those entities you should be able to use the merge method, e.g.,

    A updatedEntity = dao.merge(yourObjectFromTheHttpSession);
    

    That said, I’ve had to manually reconcile related collections to properly handle new incoming entities and remove existing entities in the past and have been unable to rely on hibernate to automagically take care of everything, so YMMV.

    From the docs:

    Copy the state of the given object onto the persistent object with the same identifier. If there is no persistent instance currently associated with the session, it will be loaded. Return the persistent instance. If the given instance is unsaved, save a copy of and return it as a newly persistent instance. The given instance does not become associated with the session. This operation cascades to associated instances if the association is mapped with cascade="merge".

    The semantics of this method are defined by JSR-220.

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

Sidebar

Related Questions

Lets say I have the following code: abstract class Animal case class Dog(name:String) extends
Lets say I have object Tom which has class Person. Class Person String Name
Lets say I have a Dictionary object: Dictionary myDictionary<int, SomeObject> = new Dictionary<string, SomeObject>();
Lets say i have the following controller: // // GET: /Courses/Edit/5 public ActionResult Edit(int
Lets say I have a div like this: <div id=test class=sourcecode> Some String </div>
Lets say I have a class that is doing something like: public class Foo
Lets say, I have a class with objects in it. namespace Class_Serialization { [Serializable]
Lets say I have several web sites on my web server, all as applications
Lets say I have an array like this: string [] Filelist = ... I
Lets say we have this code: <div id='m1'> <div class=c></div> <div class=c></div> <div class=c></div>

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.