mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-12 22:24:47 +00:00
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 static void bindQuery(NamedQuery queryAnn, Mappings mappings, boolean isD
|
|||||||
getBoolean( queryName, "org.hibernate.cacheable", hints ),
|
getBoolean( queryName, "org.hibernate.cacheable", hints ),
|
||||||
getString( queryName, "org.hibernate.cacheRegion", hints ),
|
getString( queryName, "org.hibernate.cacheRegion", hints ),
|
||||||
getTimeout( queryName, hints ),
|
getTimeout( queryName, hints ),
|
||||||
|
getLockTimeout( queryName, hints),
|
||||||
getInteger( queryName, "org.hibernate.fetchSize", hints ),
|
getInteger( queryName, "org.hibernate.fetchSize", hints ),
|
||||||
getFlushMode( queryName, hints ),
|
getFlushMode( queryName, hints ),
|
||||||
getCacheMode( 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) {
|
public static void bindNativeQuery(NamedNativeQuery queryAnn, Mappings mappings, boolean isDefault) {
|
||||||
if ( queryAnn == null ) return;
|
if ( queryAnn == null ) return;
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
|
|
||||||
import org.hibernate.CacheMode;
|
import org.hibernate.CacheMode;
|
||||||
import org.hibernate.FlushMode;
|
import org.hibernate.FlushMode;
|
||||||
|
import org.hibernate.LockOptions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Definition of a named query, defined in the mapping metadata.
|
* 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 boolean cacheable;
|
||||||
private final String cacheRegion;
|
private final String cacheRegion;
|
||||||
private final Integer timeout;
|
private final Integer timeout;
|
||||||
|
private final Integer lockTimeout;
|
||||||
private final Integer fetchSize;
|
private final Integer fetchSize;
|
||||||
private final FlushMode flushMode;
|
private final FlushMode flushMode;
|
||||||
private final Map parameterTypes;
|
private final Map parameterTypes;
|
||||||
@ -84,11 +86,30 @@ public NamedQueryDefinition(
|
|||||||
boolean readOnly,
|
boolean readOnly,
|
||||||
String comment,
|
String comment,
|
||||||
Map parameterTypes) {
|
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.name = name;
|
||||||
this.query = query;
|
this.query = query;
|
||||||
this.cacheable = cacheable;
|
this.cacheable = cacheable;
|
||||||
this.cacheRegion = cacheRegion;
|
this.cacheRegion = cacheRegion;
|
||||||
this.timeout = timeout;
|
this.timeout = timeout;
|
||||||
|
this.lockTimeout = lockTimeout;
|
||||||
this.fetchSize = fetchSize;
|
this.fetchSize = fetchSize;
|
||||||
this.flushMode = flushMode;
|
this.flushMode = flushMode;
|
||||||
this.parameterTypes = parameterTypes;
|
this.parameterTypes = parameterTypes;
|
||||||
@ -148,4 +169,8 @@ public boolean isReadOnly() {
|
|||||||
public String getComment() {
|
public String getComment() {
|
||||||
return comment;
|
return comment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Integer getLockTimeout() {
|
||||||
|
return lockTimeout;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -142,6 +142,9 @@ public Query getNamedQuery(String queryName) throws MappingException {
|
|||||||
getHQLQueryPlan( queryString, false ).getParameterMetadata()
|
getHQLQueryPlan( queryString, false ).getParameterMetadata()
|
||||||
);
|
);
|
||||||
query.setComment( "named HQL query " + queryName );
|
query.setComment( "named HQL query " + queryName );
|
||||||
|
if ( nqd.getLockTimeout() != null ) {
|
||||||
|
( (QueryImpl) query ).getLockOptions().setTimeOut( nqd.getLockTimeout() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
NamedSQLQueryDefinition nsqlqd = factory.getNamedSQLQuery( queryName );
|
NamedSQLQueryDefinition nsqlqd = factory.getNamedSQLQuery( queryName );
|
||||||
|
@ -53,7 +53,6 @@ public class LockTest extends BaseEntityManagerFunctionalTestCase {
|
|||||||
private static final Logger log = Logger.getLogger( LockTest.class );
|
private static final Logger log = Logger.getLogger( LockTest.class );
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@FailureExpected( jiraKey = "HHH-7356")
|
|
||||||
public void testLockTimeoutASNamedQueryHint(){
|
public void testLockTimeoutASNamedQueryHint(){
|
||||||
EntityManager em = getOrCreateEntityManager();
|
EntityManager em = getOrCreateEntityManager();
|
||||||
em.getTransaction().begin();
|
em.getTransaction().begin();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user