File tree Expand file tree Collapse file tree 1 file changed +8
-2
lines changed
hibernate-entitymanager/src/main/java/org/hibernate/jpa/internal Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change 50
50
import org .hibernate .HibernateException ;
51
51
import org .hibernate .LockMode ;
52
52
import org .hibernate .SQLQuery ;
53
+ import org .hibernate .Session ;
53
54
import org .hibernate .TypeMismatchException ;
54
55
import org .hibernate .engine .query .spi .NamedParameterDescriptor ;
55
56
import org .hibernate .engine .query .spi .OrdinalParameterDescriptor ;
56
57
import org .hibernate .engine .query .spi .ParameterMetadata ;
57
58
import org .hibernate .engine .spi .SessionFactoryImplementor ;
59
+ import org .hibernate .engine .spi .SessionImplementor ;
58
60
import org .hibernate .hql .internal .QueryExecutionRequestException ;
59
61
import org .hibernate .internal .SQLQueryImpl ;
60
62
import org .hibernate .jpa .AvailableSettings ;
@@ -416,8 +418,12 @@ private void beforeQuery() {
416
418
return ;
417
419
}
418
420
419
- // otherwise we need to flush
420
- getEntityManager ().flush ();
421
+ // otherwise we need to flush. the query itself is not required to execute in a transaction; if there is
422
+ // no transaction, the flush would throw a TransactionRequiredException which would potentially break existing
423
+ // apps, so we only do the flush if a transaction is in progress.
424
+ if ( getEntityManager ().isTransactionInProgress () ) {
425
+ getEntityManager ().flush ();
426
+ }
421
427
}
422
428
423
429
@ Override
You can’t perform that action at this time.
0 commit comments