@@ -115,32 +115,16 @@ public String getPersistenceProviderRootPackage() {
115115
116116 @ Override
117117 public Map <String , Object > getJpaPropertyMap (PersistenceUnitInfo pui ) {
118- Map <String , Object > jpaProperties = getJpaPropertyMap ();
119-
120- if (this .jpaDialect .prepareConnection && pui .getTransactionType () != PersistenceUnitTransactionType .JTA ) {
121- // Hibernate 5.1/5.2: manually enforce connection release mode ON_CLOSE (the former default)
122- try {
123- // Try Hibernate 5.2
124- AvailableSettings .class .getField ("CONNECTION_HANDLING" );
125- jpaProperties .put ("hibernate.connection.handling_mode" , "DELAYED_ACQUISITION_AND_HOLD" );
126- }
127- catch (NoSuchFieldException ex ) {
128- // Try Hibernate 5.1
129- try {
130- AvailableSettings .class .getField ("ACQUIRE_CONNECTIONS" );
131- jpaProperties .put ("hibernate.connection.release_mode" , "ON_CLOSE" );
132- }
133- catch (NoSuchFieldException ex2 ) {
134- // on Hibernate 5.0.x or lower - no need to change the default there
135- }
136- }
137- }
138-
139- return jpaProperties ;
118+ return buildJpaPropertyMap (this .jpaDialect .prepareConnection &&
119+ pui .getTransactionType () != PersistenceUnitTransactionType .JTA );
140120 }
141121
142122 @ Override
143123 public Map <String , Object > getJpaPropertyMap () {
124+ return buildJpaPropertyMap (this .jpaDialect .prepareConnection );
125+ }
126+
127+ private Map <String , Object > buildJpaPropertyMap (boolean connectionReleaseOnClose ) {
144128 Map <String , Object > jpaProperties = new HashMap <>();
145129
146130 if (getDatabasePlatform () != null ) {
@@ -160,6 +144,25 @@ public Map<String, Object> getJpaPropertyMap() {
160144 jpaProperties .put (AvailableSettings .SHOW_SQL , "true" );
161145 }
162146
147+ if (connectionReleaseOnClose ) {
148+ // Hibernate 5.1/5.2: manually enforce connection release mode ON_CLOSE (the former default)
149+ try {
150+ // Try Hibernate 5.2
151+ AvailableSettings .class .getField ("CONNECTION_HANDLING" );
152+ jpaProperties .put ("hibernate.connection.handling_mode" , "DELAYED_ACQUISITION_AND_HOLD" );
153+ }
154+ catch (NoSuchFieldException ex ) {
155+ // Try Hibernate 5.1
156+ try {
157+ AvailableSettings .class .getField ("ACQUIRE_CONNECTIONS" );
158+ jpaProperties .put ("hibernate.connection.release_mode" , "ON_CLOSE" );
159+ }
160+ catch (NoSuchFieldException ex2 ) {
161+ // on Hibernate 5.0.x or lower - no need to change the default there
162+ }
163+ }
164+ }
165+
163166 return jpaProperties ;
164167 }
165168
0 commit comments