Skip to content

Commit 997ca5c

Browse files
committed
Query termination for JPA 2.1 StoredProcedureQuery.execute() method
Includes backported support for JPA 2.2 getResultStream() method. Issue: SPR-16826
1 parent a54bc66 commit 997ca5c

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

spring-orm/src/main/java/org/springframework/orm/jpa/SharedEntityManagerCreator.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -65,9 +65,9 @@ public abstract class SharedEntityManagerCreator {
6565

6666
private static final Class<?>[] NO_ENTITY_MANAGER_INTERFACES = new Class<?>[0];
6767

68-
private static final Set<String> transactionRequiringMethods = new HashSet<String>(6);
68+
private static final Set<String> transactionRequiringMethods = new HashSet<String>(8);
6969

70-
private static final Set<String> queryTerminationMethods = new HashSet<String>(3);
70+
private static final Set<String> queryTerminatingMethods = new HashSet<String>(8);
7171

7272
static {
7373
transactionRequiringMethods.add("joinTransaction");
@@ -77,9 +77,11 @@ public abstract class SharedEntityManagerCreator {
7777
transactionRequiringMethods.add("remove");
7878
transactionRequiringMethods.add("refresh");
7979

80-
queryTerminationMethods.add("getResultList");
81-
queryTerminationMethods.add("getSingleResult");
82-
queryTerminationMethods.add("executeUpdate");
80+
queryTerminatingMethods.add("execute"); // JPA 2.1 StoredProcedureQuery
81+
queryTerminatingMethods.add("executeUpdate");
82+
queryTerminatingMethods.add("getSingleResult");
83+
queryTerminatingMethods.add("getResultList");
84+
queryTerminatingMethods.add("getResultStream");
8385
}
8486

8587

@@ -376,7 +378,7 @@ else if (targetClass.isInstance(proxy)) {
376378
throw ex.getTargetException();
377379
}
378380
finally {
379-
if (queryTerminationMethods.contains(method.getName())) {
381+
if (queryTerminatingMethods.contains(method.getName())) {
380382
// Actual execution of the query: close the EntityManager right
381383
// afterwards, since that was the only reason we kept it open.
382384
EntityManagerFactoryUtils.closeEntityManager(this.em);

0 commit comments

Comments
 (0)