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.Arrays;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
@ -25,6 +26,7 @@ import javax.persistence.Parameter;
|
||||||
import javax.persistence.TemporalType;
|
import javax.persistence.TemporalType;
|
||||||
|
|
||||||
import org.hibernate.CacheMode;
|
import org.hibernate.CacheMode;
|
||||||
|
import org.hibernate.Filter;
|
||||||
import org.hibernate.FlushMode;
|
import org.hibernate.FlushMode;
|
||||||
import org.hibernate.HibernateException;
|
import org.hibernate.HibernateException;
|
||||||
import org.hibernate.LockMode;
|
import org.hibernate.LockMode;
|
||||||
|
@ -251,6 +253,11 @@ public abstract class AbstractProducedQuery<R> implements QueryImplementor<R> {
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public QueryImplementor setLockMode(LockModeType lockModeType) {
|
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 ) );
|
lockOptions.setLockMode( LockModeTypeHelper.getLockMode( lockModeType ) );
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -1171,4 +1178,10 @@ public abstract class AbstractProducedQuery<R> implements QueryImplementor<R> {
|
||||||
? binding.getBindType()
|
? binding.getBindType()
|
||||||
: defaultType;
|
: 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
|
@Override
|
||||||
public NativeQueryImplementor setLockMode(LockModeType lockModeType) {
|
public NativeQueryImplementor setLockMode(LockModeType lockModeType) {
|
||||||
super.setLockMode( lockModeType );
|
throw new IllegalStateException( "Illegal attempt to set lock mode on a native SQL query" );
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue