Return-Path: X-Original-To: apmail-openjpa-users-archive@minotaur.apache.org Delivered-To: apmail-openjpa-users-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 99CDAD557 for ; Wed, 22 Aug 2012 23:18:58 +0000 (UTC) Received: (qmail 84940 invoked by uid 500); 22 Aug 2012 23:18:58 -0000 Delivered-To: apmail-openjpa-users-archive@openjpa.apache.org Received: (qmail 84904 invoked by uid 500); 22 Aug 2012 23:18:58 -0000 Mailing-List: contact users-help@openjpa.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@openjpa.apache.org Delivered-To: mailing list users@openjpa.apache.org Received: (qmail 84894 invoked by uid 99); 22 Aug 2012 23:18:58 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 22 Aug 2012 23:18:58 +0000 X-ASF-Spam-Status: No, hits=3.0 required=5.0 tests=FORGED_YAHOO_RCVD,SPF_NEUTRAL,URI_HEX X-Spam-Check-By: apache.org Received-SPF: neutral (nike.apache.org: local policy) Received: from [216.139.236.26] (HELO sam.nabble.com) (216.139.236.26) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 22 Aug 2012 23:18:51 +0000 Received: from jim.nabble.com ([192.168.236.80]) by sam.nabble.com with esmtp (Exim 4.72) (envelope-from ) id 1T4KBy-0003XX-2P for users@openjpa.apache.org; Wed, 22 Aug 2012 16:18:30 -0700 Date: Wed, 22 Aug 2012 16:18:30 -0700 (PDT) From: garpinc To: users@openjpa.apache.org Message-ID: <1345677510066-7580918.post@n2.nabble.com> In-Reply-To: <1345667358281-7580917.post@n2.nabble.com> References: <1345667358281-7580917.post@n2.nabble.com> Subject: Re: Duplicate entry issue with multithreaded application MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit I think above should work but in anycase if I change to AUTO id generation then I get this exception instead which is a unique violation on an alternate key for that table. It was looked up before in the transaction but another thread also looked it up found it not to be there and performed the same operation ahead of this thread's flush. So what can be done to address this case? What I want is for that if there is a duplicate at time of insert then it should resolve by requerying the object and using an instance of it in place of the one it's trying to save. equals and hashcode are overridden. Caused by: org.apache.openjpa.persistence.EntityExistsException: Duplicate entry 'dca2db371c29a90789ba0bcbda5fc8a0808b4310-734f1c627a629e194f9ea9c' for key 'U_NZURTPK_URIHASH' {prepstmnt 317546907 INSERT INTO anzouritopk (pk, datasetUri, datasetUriHash, persistedFully, typeUri, typeUriHash, uri, uriHash) VALUES (?, ?, ?, ?, ?, ?, ?, ?) [params=(long) 5421, (Reader) java.io.StringReader@1ea310d2, (String) N/A, (int) 0, (Reader) java.io.StringReader@63a55ab4, (String) 734f1c627a629e194f9ea9cf0990bbaead59b188, (Reader) java.io.StringReader@7ce61287, (String) dca2db371c29a90789ba0bcbda5fc8a0808b4310]} [code=1062, state=23000] FailedObject: com.cambridgesemantics.anzo.relationalreplicator.jpa.model.AnzoURIToPKImpl@627e3c5f at org.apache.openjpa.jdbc.sql.DBDictionary.narrow(DBDictionary.java:4903) at org.apache.openjpa.jdbc.sql.DBDictionary.newStoreException(DBDictionary.java:4878) at org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:136) at org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:78) at org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flushAndUpdate(PreparedStatementManagerImpl.java:143) at org.apache.openjpa.jdbc.kernel.BatchingPreparedStatementManagerImpl.flushAndUpdate(BatchingPreparedStatementManagerImpl.java:79) at org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flushInternal(PreparedStatementManagerImpl.java:99) at org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flush(PreparedStatementManagerImpl.java:87) at org.apache.openjpa.jdbc.kernel.ConstraintUpdateManager.flush(ConstraintUpdateManager.java:357) at org.apache.openjpa.jdbc.kernel.ConstraintUpdateManager.flushGraph(ConstraintUpdateManager.java:349) at org.apache.openjpa.jdbc.kernel.ConstraintUpdateManager.flush(ConstraintUpdateManager.java:97) at org.apache.openjpa.jdbc.kernel.BatchingConstraintUpdateManager.flush(BatchingConstraintUpdateManager.java:59) at org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdateManager.java:103) at org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdateManager.java:76) at org.apache.openjpa.jdbc.kernel.JDBCStoreManager.flush(JDBCStoreManager.java:713) at org.apache.openjpa.kernel.DelegatingStoreManager.flush(DelegatingStoreManager.java:131) at org.apache.openjpa.datacache.DataCacheStoreManager.flush(DataCacheStoreManager.java:661) at org.apache.openjpa.kernel.DelegatingStoreManager.flush(DelegatingStoreManager.java:131) ... 19 more Caused by: org.apache.openjpa.lib.jdbc.ReportingSQLException: Duplicate entry 'dca2db371c29a90789ba0bcbda5fc8a0808b4310-734f1c627a629e194f9ea9c' for key 'U_NZURTPK_URIHASH' {prepstmnt 317546907 INSERT INTO anzouritopk (pk, datasetUri, datasetUriHash, persistedFully, typeUri, typeUriHash, uri, uriHash) VALUES (?, ?, ?, ?, ?, ?, ?, ?) [params=(long) 5421, (Reader) java.io.StringReader@1ea310d2, (String) N/A, (int) 0, (Reader) java.io.StringReader@63a55ab4, (String) 734f1c627a629e194f9ea9cf0990bbaead59b188, (Reader) java.io.StringReader@7ce61287, (String) dca2db371c29a90789ba0bcbda5fc8a0808b4310]} [code=1062, state=23000] at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.wrap(LoggingConnectionDecorator.java:247) at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.wrap(LoggingConnectionDecorator.java:223) at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.access$1000(LoggingConnectionDecorator.java:72) at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator$LoggingConnection$LoggingPreparedStatement.executeUpdate(LoggingConnectionDecorator.java:1162) at org.apache.openjpa.lib.jdbc.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:272) at org.apache.openjpa.jdbc.kernel.JDBCStoreManager$CancelPreparedStatement.executeUpdate(JDBCStoreManager.java:1741) at org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.executeUpdate(PreparedStatementManagerImpl.java:267) at org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flushAndUpdate(PreparedStatementManagerImpl.java:118) ... 32 more -- View this message in context: http://openjpa.208410.n2.nabble.com/Duplicate-entry-issue-with-multithreaded-application-tp7580917p7580918.html Sent from the OpenJPA Users mailing list archive at Nabble.com.