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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:55:25+00:00 2026-06-11T20:55:25+00:00

I have a JPA program where EclipseLink is the Persistence provider. When I merge

  • 0

I have a JPA program where EclipseLink is the Persistence provider. When I merge an user entity, change its ID, and try to merge the same user instance again, an error is thrown. I rewrite my code to illustrate my problem in the simplest way.

User user = userManager.find(1);
userManager.merge(user);
System.out.println("User is managed? "+userManager.contains(user);
user.setId(2);
userManager.merge(user);

The above code is not in a transaction context. userManager is a stateless session bean with an EntityManager injected. When executed, the console prints:

User is managed? false

Exception [EclipseLink-7251] (Eclipse Persistence Services - 2.1.3.v20110304-r9073): org.eclipse.persistence.exceptions.ValidationException
Exception Description: The attribute [id] of class [demo.model.User] is mapped to a primary key column in the database. Updates are not allowed.

The exception occurs at the second merge() invocation.

If I create a new user, sets its ID and merge it, it works:

User user = userManager.find(1);
userManager.merge(user);
System.out.println("User is managed? "+userManager.contains(user);
User newUser = new User();
newUser.setId(2);
userManager.merge(newUser);

So what is the difference between the first scenario and second one? According to the JPA specification, as long as the entity is in detached state, the merge should succeed, right?
(Assuming the entity with ID=2 exists)

Why the EclipseLink provider seems to be bothered by the fact that the user entity has been merged before?

Update: It seems to be an bug of EclipseLink. I have replaced the persistence provider from EclipseLink to Hibernate:

I change

<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>

to

<provider>org.hibernate.ejb.HibernatePersistence</provider>    

No error has been thrown.

  • 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-11T20:55:26+00:00Added an answer on June 11, 2026 at 8:55 pm

    It seems to be an bug of EclipseLink. I have changed the persistence provider from EclipseLink to Hibernate:

    from

    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    

    to

    <provider>org.hibernate.ejb.HibernatePersistence</provider>  
    

    No error has been thrown.

    The version of EclipseLink is 2.3.2. (which is shipped with the latest Glassfish application server 3.1.2).

    The version of hibernate is, as of now the latest, 4.1.7.

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

Sidebar

Related Questions

I have a JPA entity instance in the web UI layer of my application.
I have a JPA entity bean similar to the following: @Entity class License {
I have a JPA object which has a many-to-many relationship like this: @Entity public
I have a JPA entity similar to; public class Inventory { private String productname;
A have a JPA entity that has timestamp field and is distinguished by a
I have a JPA 2 Entity named Surgery . It has a member named
We have some JPA entity classes which are currently under development and wouldn't want
I have a JPA project connected to a MySQL database where my entity object
I have a JPA Entity StatsEntity which has a composite primary key that is
I have a JPA object: @Entity @Table(name=WF_GROUP) public class Group { @Id @GeneratedValue(strategy =

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.