Use EntityManager.detach
. It makes the bean no longer linked to the EntityManager. Then set the Id to the new Id (or null if automatic), change the fields that you need and persist.
More Related Contents:
- How to fix the Hibernate “object references an unsaved transient instance – save the transient instance before flushing” error
- What is the difference between persist() and merge() in JPA and Hibernate?
- JPA JoinColumn vs mappedBy
- PersistentObjectException: detached entity passed to persist thrown by JPA and Hibernate
- Difference between FetchType LAZY and EAGER in Java Persistence API?
- How to map a composite key with JPA and Hibernate?
- Hibernate Annotations – Which is better, field or property access?
- How to map an entity field whose name is a reserved word in JPA
- Do I need elements in persistence.xml?
- What’s the difference between JPA and Hibernate? [closed]
- What is the solution for the N+1 issue in JPA and Hibernate?
- JPA CascadeType.ALL does not delete orphans
- Bypass GeneratedValue in Hibernate (merge data not in db?)
- Map enum in JPA with fixed values?
- JPA: How to have one-to-many relation of the same Entity type
- Hibernate – @ElementCollection – Strange delete/insert behavior
- JPA – Persisting a One to Many relationship
- How do I properly cascade save a one-to-one, bidirectional relationship on primary key in Hibernate 3.6
- JPA: Implementing Model Hierarchy – @MappedSuperclass vs. @Inheritance
- Is there such thing CASE expression in JPQL?
- How To Define a JPA Repository Query with a Join
- Doing an “IN” query with Hibernate
- JPA, How to use the same class (entity) to map different tables?
- Specifying an Index (Non-Unique Key) Using JPA
- Disable caching in JPA (eclipselink)
- The onFlushDirty Hibernate Interceptor method is never called
- Difference between @MapKey, @MapKeyColumn and @MapKeyJoinColumn in JPA and Hibernate
- Hibernate throws strange error: Class is not mapped
- Clarifying terminology – What does “hydrating” a JPA or Hibernate entity mean when fetching the entity from the DB
- Does JPA support mapping to sql views?