openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Roger Keays (JIRA)" <>
Subject [jira] [Created] (OPENJPA-2262) Merging Deserialized Objects Reports Duplicate IDs
Date Mon, 17 Sep 2012 20:29:07 GMT
Roger Keays created OPENJPA-2262:

             Summary: Merging Deserialized Objects Reports Duplicate IDs
                 Key: OPENJPA-2262
             Project: OpenJPA
          Issue Type: Bug
          Components: kernel
    Affects Versions: 2.0.0
         Environment: Java 1.6, Postgres
            Reporter: Roger Keays

OPENJPA-792 patched a defect where putting @Id in the superclass caused primary key conflicts
in the subclasses.

I get the same error described in OPENJPA-792 when merging a deserialized instance of an object
from my domain model. I can reproduce the problem with some objects in my domain model but
not other (although the all have the same superclass which contains the @Id field).

This only occurs after deserialization and closing and opening the EntityManager.

My failing unit test looks like this.

    public void canMergeEntitiesWithMatchingIDAfterSerialization() throws 
                IOException, ClassNotFoundException {
            // setup id sequences
            Long id = System.currentTimeMillis();
            EntityManager em = DB.getPersistenceContext();
                    "SELECT setval('cms_content_id_seq', " + id + ");")
                    "SELECT setval('web_blobs_id_seq', " + id + ");")
            // persist with same id
            Server server = newServer();
            Content c = ContentTest.createValid(server);
            Blob b = BlobTest.createValid(server);
            assertEquals(c.getId(), b.getId());
            // serialize and deserialize the object
            File file = File.createTempFile("blob", "bin");
            ObjectOutput out = new ObjectOutputStream(new FileOutputStream(file));
            ObjectInputStream in = new ObjectInputStream(new FileInputStream(file));
            b = (Blob) in.readObject();
            // reopen db session and try to merge an update
            em = DB.getPersistenceContext();
            em.merge(b); // EntityExistsException

And the stacktrace is 

<openjpa-2.2.0-r422266:1244990 nonfatal store error> org.apache.openjpa.persistence.EntityNotFoundException:
Attempted to attach instance "1347912956793" of type "class ox.webcore.blobs.Blob", but this
instance is already in the datastore as type "class ox.cms.content.Content".
FailedObject: ox.webcore.blobs.Blob@162e703
	at org.apache.openjpa.kernel.VersionAttachStrategy.attach(
	at org.apache.openjpa.kernel.AttachManager.attach(
	at org.apache.openjpa.kernel.AttachManager.attach(
	at org.apache.openjpa.kernel.BrokerImpl.attach(
	at org.apache.openjpa.kernel.DelegatingBroker.attach(
	at org.apache.openjpa.persistence.EntityManagerImpl.merge(
	at ox.webcore.util.DB$DBTest.canMergeEntitiesWithMatchingIDAfterSerialization(

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

View raw message