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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:17:13+00:00 2026-06-17T16:17:13+00:00

In my Spring application, I have code that reads in XML, then fetches for

  • 0

In my Spring application, I have code that reads in XML, then fetches for example an Organization entity via JPA and then updates the fields found in the XML to the Organization and returns the Organization.

But with code like this:

Organization updated = mergeToOrganization(jaxbOrganizationPojo, originalOrganization);

I really feel like I should start the mergeToOrganization method by making a protective copy of originalOrganization instead of directly mutating it. Direct mutation leaves me feeling dirty. But alternatives to that seem to be sketchy reflection or loooong get/set boiler plate code.

Ideas? Opinions?

  • 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-17T16:17:14+00:00Added an answer on June 17, 2026 at 4:17 pm

    I don’t see what’s the problem with direct mutation as long as you handle transactions properly. But if you want to remove the entity from persistent context, assuming you’re using JPA 2.0, you can use EntityManager.detach(). This way, technically, the entity will never be marked “dirty” and you don’t have to feel bad about it. Also, make sure to use merge() to save it back and not persist(), or you’ll get many nasty exceptions.

    EDIT If you want to return a new copy of your entity, the most bullet-proof cloning method I’ve seen so far is to use ObjectOutputStream: http://javatechniques.com/blog/faster-deep-copies-of-java-objects/

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

Sidebar

Related Questions

I have written the following piece of code that reads through a given xml-file
I'm moving an application to use the Spring3 framework and I have code that
I have a spring application that uses an embedded Jetty instance. Since I am
I have a Spring application that I believe has some bottlenecks, so I'd like
I have a spring mvc application that I have broken up into separate maven
I have a web application that creates XML feeds on the fly, depending on
I have the following XML Parsing code in my application: public static XElement Parse(string
I have an application that compared an xml file to a text file, and
I have a rather strange problem. I have a very simple application that reads
I have wrote a WPF application that reads a list of movies from a

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.