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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:24:59+00:00 2026-05-26T17:24:59+00:00

Perhaps I’m over-simplifying this by only giving you a small snippet of code (and

  • 0

Perhaps I’m over-simplifying this by only giving you a small snippet of code (and I’ll post more if that is the case) but I figure, initially, less is better:

I have an entity of type Asset which has a field of type Location, which is also an entity. When I set the Location of an Asset I must also set the Location of its children.

Location location = asset.getLocation();
em.merge(location);
em.flush();

childAsset.setLocation(asset.getLocation());
em.flush();

When I run flush(), I get the following exception:

Internal Exception: java.sql.SQLIntegrityConstraintViolationException: ORA-00001: unique constraint (SWRADMIN.LOCATION_PK) violated

My question is…why is this Location object even trying to be persisted? All I’m doing is setting a variable in an entity.

This was working fine before, but we just switched to using Eclipselink and Java EE 6 and this problem popped up.

Solution?: I used the idea of “detaching” from below and made the following change:

Location location = asset.getLocation();

em.detach(childAsset);
childAsset.setLocation(asset.getLocation());
em.merge();
em.flush();

and it worked! I’m confused as to why, though…you would think the auto-syncing would do the same thing.

  • 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-26T17:25:00+00:00Added an answer on May 26, 2026 at 5:25 pm

    If the object is in managed state, then entity manager will synchronize it with the underlying database by persisting the object implicitly (probably at the end of the transaction) or explicitly when you call em.flush() method.

    You can use em.detach(entity) to detach a single entity or em.clear() to detach all the entities. Then the changes being made on an entity/entities will not get reflected in the database.

    To better handle this, you can use BMT (Bean Managed Transaction), where you have to handle the entity persistence, transaction manually.

    Edit :

    Location location = asset.getLocation();
    childAsset.setLocation(location);
    em.merge(childAsset);
    em.flush();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Perhaps i am being stupid by asking this just now, but... I notice that
Perhaps I'm having a Post-Ballmer-Peak Moment . I'm hoping that someone can help point
Perhaps there is a better way to do this, but here's where I'm at
Perhaps a stupid question, but what exactly is the purpose of this Delphi folder?:
Perhaps my brain is fried, but I'm writing a plugin that created an tweaks
Perhaps I haven't found the right post but I have been unable to set
Perhaps I'm missing something here, but it seems that anything in the object model
Perhaps my eyes are fooling me, but how is it that in .NET 2.0,
Perhaps this is mere wishful thinking, but is there a simple way (in ASP.NET)
Perhaps this is nitpicky, but I have to ask. I'm using Nokogiri to parse

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.