You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by "Jacob Nowosatka (Updated) (JIRA)" <ji...@apache.org> on 2011/11/22 00:21:39 UTC

[jira] [Updated] (OPENJPA-1671) Merge Detached Entity - Attempted to attach instance * but this instance is already in the datastore

     [ https://issues.apache.org/jira/browse/OPENJPA-1671?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jacob Nowosatka updated OPENJPA-1671:
-------------------------------------

    Attachment: TestDetachedEntities.java

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.

Thanks
                
> Merge Detached Entity - Attempted to attach instance * but this instance is already in the datastore
> ----------------------------------------------------------------------------------------------------
>
>                 Key: OPENJPA-1671
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-1671
>             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: TestDetachedEntities.java
>
>
> @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: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira