HHH-8521 LockMode should be checked on query execution, not during call

to setLockMode
This commit is contained in:
Brett Meyer 2013-09-18 18:01:31 -04:00 committed by Steve Ebersole
parent 903321fe92
commit 2243fa68ff
2 changed files with 10 additions and 7 deletions

View File

@ -441,6 +441,7 @@ public class QueryImpl<X> extends AbstractQueryImpl<X> implements TypedQuery<X>,
@SuppressWarnings({ "unchecked", "RedundantCast" })
public List<X> getResultList() {
getEntityManager().checkOpen( true );
checkTransaction();
beforeQuery();
try {
return query.list();
@ -486,6 +487,7 @@ public class QueryImpl<X> extends AbstractQueryImpl<X> implements TypedQuery<X>,
@SuppressWarnings({ "unchecked", "RedundantCast" })
public X getSingleResult() {
getEntityManager().checkOpen( true );
checkTransaction();
beforeQuery();
try {
final List<X> result = query.list();

View File

@ -128,13 +128,6 @@ public abstract class AbstractQueryImpl<X> extends BaseQueryImpl implements Type
throw new IllegalStateException( "Illegal attempt to set lock mode on a non-SELECT query" );
}
// todo : technically this check should be on execution of the query, not here : HHH-8521
if ( lockModeType != LockModeType.NONE ) {
if (! getEntityManager().isTransactionInProgress()) {
throw new TransactionRequiredException( "no transaction is in progress" );
}
}
if ( ! canApplyAliasSpecificLockModeHints() ) {
throw new IllegalStateException( "Not a JPAQL/Criteria query" );
}
@ -212,4 +205,12 @@ public abstract class AbstractQueryImpl<X> extends BaseQueryImpl implements Type
public AbstractQueryImpl<X> setFlushMode(FlushModeType jpaFlushMode) {
return (AbstractQueryImpl<X>) super.setFlushMode( jpaFlushMode );
}
protected void checkTransaction() {
if ( jpaLockMode != null && jpaLockMode != LockModeType.NONE ) {
if ( !getEntityManager().isTransactionInProgress() ) {
throw new TransactionRequiredException( "no transaction is in progress" );
}
}
}
}