HHH-7356 javax.persistence.lock.timeout hint is ignored by @NamedQuery

This commit is contained in:
Strong Liu 2012-05-29 17:44:09 +08:00
parent 2036d1479f
commit 4266cd3585
4 changed files with 39 additions and 1 deletions

View File

@ -71,6 +71,7 @@ public static void bindQuery(NamedQuery queryAnn, Mappings mappings, boolean isD
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 static void bindQuery(NamedQuery queryAnn, Mappings mappings, boolean isD
}
}
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;

View File

@ -28,6 +28,7 @@
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 NamedQueryDefinition(
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 boolean isReadOnly() {
public String getComment() {
return comment;
}
public Integer getLockTimeout() {
return lockTimeout;
}
}

View File

@ -142,6 +142,9 @@ public Query getNamedQuery(String queryName) throws MappingException {
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 );

View File

@ -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();