openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jacob Nowosatka (Updated) (JIRA)" <>
Subject [jira] [Updated] (OPENJPA-1671) Merge Detached Entity - Attempted to attach instance * but this instance is already in the datastore
Date Mon, 21 Nov 2011 23:21:39 GMT


Jacob Nowosatka updated OPENJPA-1671:


I was unable to recreate the exact issue that you are describing. My test case is attached.
I will note that a few other variations of the attached test case were attempted but were
unable to reproduce issue.

I was able to get the same error, but the cause seems to be a bit different then what was
described. In my case, I ran into the error when there was a User entity with the name "USER"
in the persistence context and then tried to merge the new UserExtended entity.

Because I was unable to recreate the issue, I will be closing this issue. If you feel the
problem is still relevant, please reopen with more information on the setup and a test case.

> Merge Detached Entity - Attempted to attach instance * but this instance is already in
the datastore
> ----------------------------------------------------------------------------------------------------
>                 Key: OPENJPA-1671
>                 URL:
>             Project: OpenJPA
>          Issue Type: Bug
>    Affects Versions: 1.2.2
>         Environment: Windows XP, JDK 1.6.0_16, Tomcat 6, OpenJPA 1.2.2, Oracle 10g
>            Reporter: Seth Jackson
>         Attachments:
> @Entity
> @Table(name="USERS")
> @Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
> public class User implements Serializable {
>   @Id
>   @Column(name="user_name")
>   private String userName;
>   /* getter / setter */
> }
> @Entity
> public class UserExtended extends User {
>     @Column (name="phone)
>     private String phone;
>   /* getter / setter */
> }
> // Save currently existing user (detached entity)
> UserExtended user = new UserExtended();
> user.setUserName("USER");
> user.setPhone("111-222-3333");
> entityManager.merge(user);
> Receive exception:
> Attempted to attach instance "USER" of type "class com.UserExtended", but this instance
is already in the datastore as type "class com.User".
> I've narrowed it down to this:
> When the merge() is called on the UserExtended class, OpenJPA retrieves the data from
the user table to perform the merge. When it retrieves this data, I believe it's retrieving
it in the form of a User entity, not a UserExtended entity, causing the merge to fail.
> If I retrieve the UserExtended entity from the database, change a value, then merge()
I receive no errors.

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:!default.jspa
For more information on JIRA, see:


View raw message