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


@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.
-
You can reply to this email to add a comment to the issue online.

Reply via email to