Fix setLockMode
This commit is contained in:
parent
bec73b3bd3
commit
8f812730d1
|
@ -11,6 +11,7 @@ import java.util.ArrayList;
|
|||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
|
@ -25,6 +26,7 @@ import javax.persistence.Parameter;
|
|||
import javax.persistence.TemporalType;
|
||||
|
||||
import org.hibernate.CacheMode;
|
||||
import org.hibernate.Filter;
|
||||
import org.hibernate.FlushMode;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.LockMode;
|
||||
|
@ -251,6 +253,11 @@ public abstract class AbstractProducedQuery<R> implements QueryImplementor<R> {
|
|||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public QueryImplementor setLockMode(LockModeType lockModeType) {
|
||||
if ( !LockModeType.NONE.equals( lockModeType ) ) {
|
||||
if ( !isSelect() ) {
|
||||
throw new IllegalStateException( "Illegal attempt to set lock mode on a non-SELECT query" );
|
||||
}
|
||||
}
|
||||
lockOptions.setLockMode( LockModeTypeHelper.getLockMode( lockModeType ) );
|
||||
return this;
|
||||
}
|
||||
|
@ -1171,4 +1178,10 @@ public abstract class AbstractProducedQuery<R> implements QueryImplementor<R> {
|
|||
? binding.getBindType()
|
||||
: defaultType;
|
||||
}
|
||||
|
||||
private boolean isSelect() {
|
||||
return getProducer().getFactory().getQueryPlanCache()
|
||||
.getHQLQueryPlan( getQueryString(), false, Collections.<String, Filter>emptyMap() )
|
||||
.isSelect();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -483,8 +483,7 @@ public class NativeQueryImpl extends AbstractProducedQuery<Object> implements Na
|
|||
|
||||
@Override
|
||||
public NativeQueryImplementor setLockMode(LockModeType lockModeType) {
|
||||
super.setLockMode( lockModeType );
|
||||
return this;
|
||||
throw new IllegalStateException( "Illegal attempt to set lock mode on a native SQL query" );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue