HHH-7356 javax.persistence.lock.timeout hint is ignored by @NamedQuery
This commit is contained in:
parent
2036d1479f
commit
4266cd3585
|
@ -71,6 +71,7 @@ public abstract class QueryBinder {
|
|||
getBoolean( queryName, "org.hibernate.cacheable", hints ),
|
||||
getString( queryName, "org.hibernate.cacheRegion", hints ),
|
||||
getTimeout( queryName, hints ),
|
||||
getLockTimeout( queryName, hints),
|
||||
getInteger( queryName, "org.hibernate.fetchSize", hints ),
|
||||
getFlushMode( queryName, hints ),
|
||||
getCacheMode( queryName, hints ),
|
||||
|
@ -89,6 +90,16 @@ public abstract class QueryBinder {
|
|||
}
|
||||
}
|
||||
|
||||
private static Integer getLockTimeout(String queryName, QueryHint[] hints) {
|
||||
Integer timeout = getInteger( queryName, "javax.persistence.lock.timeout", hints );
|
||||
|
||||
if ( timeout != null ) {
|
||||
// convert milliseconds to seconds
|
||||
timeout = (int)Math.round(timeout.doubleValue() / 1000.0 );
|
||||
}
|
||||
return timeout;
|
||||
}
|
||||
|
||||
|
||||
public static void bindNativeQuery(NamedNativeQuery queryAnn, Mappings mappings, boolean isDefault) {
|
||||
if ( queryAnn == null ) return;
|
||||
|
|
|
@ -28,6 +28,7 @@ import java.util.Map;
|
|||
|
||||
import org.hibernate.CacheMode;
|
||||
import org.hibernate.FlushMode;
|
||||
import org.hibernate.LockOptions;
|
||||
|
||||
/**
|
||||
* Definition of a named query, defined in the mapping metadata.
|
||||
|
@ -40,6 +41,7 @@ public class NamedQueryDefinition implements Serializable {
|
|||
private final boolean cacheable;
|
||||
private final String cacheRegion;
|
||||
private final Integer timeout;
|
||||
private final Integer lockTimeout;
|
||||
private final Integer fetchSize;
|
||||
private final FlushMode flushMode;
|
||||
private final Map parameterTypes;
|
||||
|
@ -84,11 +86,30 @@ public class NamedQueryDefinition implements Serializable {
|
|||
boolean readOnly,
|
||||
String comment,
|
||||
Map parameterTypes) {
|
||||
this(name, query, cacheable, cacheRegion,
|
||||
timeout, LockOptions.WAIT_FOREVER, fetchSize,
|
||||
flushMode, cacheMode, readOnly, comment, parameterTypes);
|
||||
}
|
||||
|
||||
public NamedQueryDefinition(
|
||||
String name,
|
||||
String query,
|
||||
boolean cacheable,
|
||||
String cacheRegion,
|
||||
Integer timeout,
|
||||
Integer lockTimeout,
|
||||
Integer fetchSize,
|
||||
FlushMode flushMode,
|
||||
CacheMode cacheMode,
|
||||
boolean readOnly,
|
||||
String comment,
|
||||
Map parameterTypes) {
|
||||
this.name = name;
|
||||
this.query = query;
|
||||
this.cacheable = cacheable;
|
||||
this.cacheRegion = cacheRegion;
|
||||
this.timeout = timeout;
|
||||
this.lockTimeout = lockTimeout;
|
||||
this.fetchSize = fetchSize;
|
||||
this.flushMode = flushMode;
|
||||
this.parameterTypes = parameterTypes;
|
||||
|
@ -148,4 +169,8 @@ public class NamedQueryDefinition implements Serializable {
|
|||
public String getComment() {
|
||||
return comment;
|
||||
}
|
||||
|
||||
public Integer getLockTimeout() {
|
||||
return lockTimeout;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -142,6 +142,9 @@ public abstract class AbstractSessionImpl implements Serializable, SharedSession
|
|||
getHQLQueryPlan( queryString, false ).getParameterMetadata()
|
||||
);
|
||||
query.setComment( "named HQL query " + queryName );
|
||||
if ( nqd.getLockTimeout() != null ) {
|
||||
( (QueryImpl) query ).getLockOptions().setTimeOut( nqd.getLockTimeout() );
|
||||
}
|
||||
}
|
||||
else {
|
||||
NamedSQLQueryDefinition nsqlqd = factory.getNamedSQLQuery( queryName );
|
||||
|
|
|
@ -53,7 +53,6 @@ public class LockTest extends BaseEntityManagerFunctionalTestCase {
|
|||
private static final Logger log = Logger.getLogger( LockTest.class );
|
||||
|
||||
@Test
|
||||
@FailureExpected( jiraKey = "HHH-7356")
|
||||
public void testLockTimeoutASNamedQueryHint(){
|
||||
EntityManager em = getOrCreateEntityManager();
|
||||
em.getTransaction().begin();
|
||||
|
|
Loading…
Reference in New Issue