You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by mi...@apache.org on 2022/03/12 17:06:11 UTC

[olingo-odata2] 01/02: [OLINGO-1269] Release database connection when updating a not-existed entity

This is an automated email from the ASF dual-hosted git repository.

mibo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/olingo-odata2.git

commit 43a717cdaf5a6e4795af7705f46cd38689d6a606
Author: Wallace Wan <wa...@sap.com>
AuthorDate: Tue Jun 5 10:57:59 2018 +0800

    [OLINGO-1269] Release database connection when updating a not-existed entity
---
 .../odata2/jpa/processor/core/access/data/JPAProcessorImpl.java    | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAProcessorImpl.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAProcessorImpl.java
index e8f3070..2aaef0d 100644
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAProcessorImpl.java
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAProcessorImpl.java
@@ -365,8 +365,9 @@ public class JPAProcessorImpl implements JPAProcessor {
       final InputStream content, final Map<String, Object> properties, final String requestContentType)
       throws ODataJPAModelException, ODataJPARuntimeException {
     Object jpaEntity = null;
+    boolean isLocalTransaction = false;
     try {
-      boolean isLocalTransaction = setTransaction();
+      isLocalTransaction = setTransaction();
       jpaEntity = readEntity(new JPAQueryBuilder(oDataJPAContext).build(updateView));
 
       if (jpaEntity == null) {
@@ -402,6 +403,10 @@ public class JPAProcessorImpl implements JPAProcessor {
       em.getTransaction().rollback();
       throw ODataJPARuntimeException.throwException(
           ODataJPARuntimeException.ERROR_JPQL_QUERY_CREATE, e);
+    } finally {
+      if (isLocalTransaction && oDataJPAContext.getODataJPATransaction().isActive()) {
+          oDataJPAContext.getODataJPATransaction().rollback();
+      }
     }
     return jpaEntity;
   }