From 32d36f6ea984a8dabf8655352244be1510e03081 Mon Sep 17 00:00:00 2001 From: Strong Liu Date: Tue, 29 May 2012 16:58:28 +0800 Subject: [PATCH] HHH-7356 add failure expected test --- .../org/hibernate/cfg/annotations/QueryBinder.java | 2 +- .../java/org/hibernate/ejb/test/lock/LockTest.java | 13 +++++++++++++ .../hibernate/ejb/test/lock/UnversionedLock.java | 4 ++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/annotations/QueryBinder.java b/hibernate-core/src/main/java/org/hibernate/cfg/annotations/QueryBinder.java index 1302c72663..a11b2b999f 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/annotations/QueryBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/annotations/QueryBinder.java @@ -426,7 +426,7 @@ public abstract class QueryBinder { if ( timeout != null ) { // convert milliseconds to seconds - timeout = new Integer ((int)Math.round(timeout.doubleValue() / 1000.0 ) ); + timeout = (int)Math.round(timeout.doubleValue() / 1000.0 ); } else { // timeout is already in seconds diff --git a/hibernate-entitymanager/src/matrix/java/org/hibernate/ejb/test/lock/LockTest.java b/hibernate-entitymanager/src/matrix/java/org/hibernate/ejb/test/lock/LockTest.java index d9bcddce8f..417dde60b9 100644 --- a/hibernate-entitymanager/src/matrix/java/org/hibernate/ejb/test/lock/LockTest.java +++ b/hibernate-entitymanager/src/matrix/java/org/hibernate/ejb/test/lock/LockTest.java @@ -29,6 +29,8 @@ import org.hibernate.dialect.PostgreSQL81Dialect; import org.hibernate.dialect.SybaseASE15Dialect; import org.hibernate.ejb.AvailableSettings; import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase; +import org.hibernate.internal.AbstractSessionImpl; +import org.hibernate.internal.QueryImpl; import org.hibernate.testing.*; import org.jboss.logging.Logger; import org.junit.Test; @@ -50,6 +52,17 @@ import static org.junit.Assert.*; 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(); + Query query = em.createNamedQuery( "getAll" ); + query.setLockMode( LockModeType.PESSIMISTIC_READ ); + int timeout = ((QueryImpl)(((org.hibernate.ejb.QueryImpl)query).getHibernateQuery())).getLockOptions().getTimeOut(); + assertEquals( 3, timeout ); + } + @Test public void testFindWithTimeoutHint() { EntityManager em = getOrCreateEntityManager(); diff --git a/hibernate-entitymanager/src/matrix/java/org/hibernate/ejb/test/lock/UnversionedLock.java b/hibernate-entitymanager/src/matrix/java/org/hibernate/ejb/test/lock/UnversionedLock.java index 7cda34b298..300c0b09f8 100644 --- a/hibernate-entitymanager/src/matrix/java/org/hibernate/ejb/test/lock/UnversionedLock.java +++ b/hibernate-entitymanager/src/matrix/java/org/hibernate/ejb/test/lock/UnversionedLock.java @@ -3,11 +3,15 @@ package org.hibernate.ejb.test.lock; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; +import javax.persistence.NamedQuery; +import javax.persistence.QueryHint; /** * @author Emmanuel Bernard */ @Entity +@NamedQuery(name = "getAll", query = "select u from UnversionedLock u", +hints = @QueryHint( name = "javax.persistence.lock.timeout", value = "3000")) public class UnversionedLock { @Id @GeneratedValue