[
https://issues.apache.org/jira/browse/OPENJPA-2639?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16257708#comment-16257708
]
Anirban Kundu commented on OPENJPA-2639:
----------------------------------------
Doing a RETURN NEW does not work. You have duplicate entries - one in the
master table and another in partitioned table. A bad workaround was discussed
in
https://stackoverflow.com/questions/22026354/insert-trigger-ends-up-inserting-duplicate-rows-in-partitioned-table.
> OptimisticLock on Partitioned tables
> ------------------------------------
>
> Key: OPENJPA-2639
> URL: https://issues.apache.org/jira/browse/OPENJPA-2639
> Project: OpenJPA
> Issue Type: Bug
> Components: jdbc
> Affects Versions: 2.3.0, 2.4.0, 2.4.1
> Reporter: Andrej Badinka
>
> We created partition tables as it is described in the guide on
> http://www.postgresql.org/docs/9.1/static/ddl-partitioning.html .
> I have a function that inserts records to partition table depending on date
> and a trigger that calls that function, like in the documentation.
> When i try to persist new entity in transaction to this partitioned
> log_table, I get an exception on commiting:
> {quote}
> Caused by: <openjpa-2.3.0-r422266:1540826 nonfatal store error>
> org.apache.openjpa.persistence.OptimisticLockException: An optimistic lock
> violation was detected when flushing object instance
> "...entities.LogTable@4a6e9cd6" to the data store. This indicates that the
> object was concurrently modified in another transaction.
> FailedObject: ...entities.LogTable@4a6e9cd6
> at
> org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flushAndUpdate(PreparedStatementManagerImpl.java:124)
> {quote}
> Near that lines there is a code
> {quote}
> try {
> int count = executeUpdate(stmnt, sql, row);
> if (count != 1) {
> logSQLWarnings(stmnt);
> Object failed = row.getFailedObject();
> if (failed != null)
> _exceptions.add(new OptimisticException(failed));
> {quote}
> that is causing this exception I assume. On Postgres page there is an issue
> regarding this
> http://www.postgresql.org/message-id/[email protected] and
> they state that the behaviour of returning 0 is common.
> The difference in inserting on normal table and partitioned table is:
> When I insert one record manualy using INSERT on partitioned table it works,
> but returns "Query returned successfully: *0 rows affected*, 54 ms execution
> time."
> Without the trigger, the manual INSERT command returns "Query returned
> successfully: *one row affected*, 51 ms execution time."
> Without the trigger, it works OK in java code, so the java code should be ok.
> I do nothing exceptional for persisting the entity.
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)