Author: steve.ebersole(a)jboss.com
Date: 2006-09-01 09:41:58 -0400 (Fri, 01 Sep 2006)
New Revision: 10395
Added:
trunk/Hibernate3/test/org/hibernate/test/jpa/ql/NativeQueryTest.java
Modified:
trunk/Hibernate3/test/org/hibernate/test/jpa/JPAComplianceSuite.java
trunk/Hibernate3/test/org/hibernate/test/jpa/lock/RepeatableReadTest.java
Log:
minor JPA-related test enhancements
Modified: trunk/Hibernate3/test/org/hibernate/test/jpa/JPAComplianceSuite.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/jpa/JPAComplianceSuite.java 2006-09-01
12:43:14 UTC (rev 10394)
+++ trunk/Hibernate3/test/org/hibernate/test/jpa/JPAComplianceSuite.java 2006-09-01
13:41:58 UTC (rev 10395)
@@ -8,6 +8,7 @@
import org.hibernate.test.jpa.proxy.JPAProxyTest;
import org.hibernate.test.jpa.fetch.FetchingTest;
import org.hibernate.test.jpa.ql.JPAQLComplianceTest;
+import org.hibernate.test.jpa.ql.NativeQueryTest;
/**
* @author Steve Ebersole
@@ -20,6 +21,7 @@
suite.addTest( JPAProxyTest.suite() );
suite.addTest( FetchingTest.suite() );
suite.addTest( JPAQLComplianceTest.suite() );
+ suite.addTest( NativeQueryTest.suite() );
suite.addTest( RemovedEntityTest.suite() );
return suite;
}
Modified: trunk/Hibernate3/test/org/hibernate/test/jpa/lock/RepeatableReadTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/jpa/lock/RepeatableReadTest.java 2006-09-01
12:43:14 UTC (rev 10394)
+++ trunk/Hibernate3/test/org/hibernate/test/jpa/lock/RepeatableReadTest.java 2006-09-01
13:41:58 UTC (rev 10395)
@@ -4,6 +4,8 @@
import org.hibernate.Transaction;
import org.hibernate.LockMode;
import org.hibernate.StaleObjectStateException;
+import org.hibernate.exception.SQLGrammarException;
+import org.hibernate.dialect.SQLServerDialect;
import org.hibernate.test.jpa.AbstractJPATest;
import org.hibernate.test.jpa.Item;
import org.hibernate.test.jpa.Part;
@@ -65,7 +67,12 @@
assertEquals( "encountered non-repeatable read", check, item2.getName() );
assertEquals( "encountered non-repeatable read", initialVersion,
item2.getVersion() );
+ t1.commit();
+ s1.close();
+
// clean up
+ s1 = getSessions().openSession();
+ t1 = s1.beginTransaction();
s1.createQuery( "delete Item" ).executeUpdate();
t1.commit();
s1.close();
@@ -117,8 +124,25 @@
catch( StaleObjectStateException expected ) {
// this is the expected behavior
}
+ catch( SQLGrammarException t ) {
+ if ( getDialect() instanceof SQLServerDialect ) {
+ // sql-server (using snapshot isolation) reports this as a grammar exception /:)
+ //
+ // not to mention that it seems to "lose track" of the transaction in this
scenario...
+ t1.rollback();
+ t1 = s1.beginTransaction();
+ }
+ else {
+ throw t;
+ }
+ }
+ t1.commit();
+ s1.close();
+
// clean up
+ s1 = getSessions().openSession();
+ t1 = s1.beginTransaction();
s1.createQuery( "delete Item" ).executeUpdate();
t1.commit();
s1.close();
@@ -159,7 +183,12 @@
assertTrue( part == part2 );
assertEquals( "encountered non-repeatable read", check, part2.getName() );
+ t1.commit();
+ s1.close();
+
// clean up
+ s1 = getSessions().openSession();
+ t1 = s1.beginTransaction();
s1.delete( part );
t1.commit();
s1.close();
Added: trunk/Hibernate3/test/org/hibernate/test/jpa/ql/NativeQueryTest.java
===================================================================
--- trunk/Hibernate3/test/org/hibernate/test/jpa/ql/NativeQueryTest.java 2006-09-01
12:43:14 UTC (rev 10394)
+++ trunk/Hibernate3/test/org/hibernate/test/jpa/ql/NativeQueryTest.java 2006-09-01
13:41:58 UTC (rev 10395)
@@ -0,0 +1,29 @@
+package org.hibernate.test.jpa.ql;
+
+import org.hibernate.test.jpa.AbstractJPATest;
+import org.hibernate.Session;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * todo: describe NativeQueryTest
+ *
+ * @author Steve Ebersole
+ */
+public class NativeQueryTest extends AbstractJPATest {
+ public NativeQueryTest(String name) {
+ super( name );
+ }
+
+ public static Test suite() {
+ return new TestSuite( NativeQueryTest.class );
+ }
+
+ public void testJpaStylePositionalParametersInNativeSql() {
+ Session s = openSession();
+ s.beginTransaction();
+ s.createSQLQuery( "select NAME from EJB3_ITEM where ITEM_ID = ?1"
).setParameter( "1", "123" ).list();
+ s.getTransaction().commit();
+ s.close();
+ }
+}