diff --git a/build.gradle b/build.gradle index 097e4261f1..e49bd69145 100644 --- a/build.gradle +++ b/build.gradle @@ -137,6 +137,8 @@ subprojects { subProject -> testRuntime( libraries.h2 ) testRuntime( libraries.woodstox ) + testRuntime( 'org.mariadb.jdbc:mariadb-java-client:1.1.7' ) + // 6.6 gave me some NPE problems from within checkstyle... checkstyle 'com.puppycrawl.tools:checkstyle:6.5' } @@ -189,9 +191,9 @@ subprojects { subProject -> systemProperties['hibernate.test.validatefailureexpected'] = true systemProperties += System.properties.findAll { it.key.startsWith( "hibernate.") } -// beforeTest { descriptor -> -// println "Starting test: " + descriptor -// } + beforeTest { descriptor -> + println "Starting test: " + descriptor + } // afterTest { descriptor -> // println "Completed test: " + descriptor diff --git a/databases/mariadb/resources/hibernate.properties b/databases/mariadb/resources/hibernate.properties index 96c91ee4ee..d39681f02b 100644 --- a/databases/mariadb/resources/hibernate.properties +++ b/databases/mariadb/resources/hibernate.properties @@ -5,7 +5,7 @@ # See the lgpl.txt file in the root directory or . # -hibernate.dialect = +hibernate.dialect org.hibernate.dialect.MySQL5Dialect hibernate.connection.driver_class org.mariadb.jdbc.Driver hibernate.connection.url jdbc:mariadb://localhost/hibernate_orm_test hibernate.connection.username hibernate_orm_test diff --git a/hibernate-core/hibernate-core.gradle b/hibernate-core/hibernate-core.gradle index b3775d5b30..55c326ec94 100644 --- a/hibernate-core/hibernate-core.gradle +++ b/hibernate-core/hibernate-core.gradle @@ -134,3 +134,10 @@ xjc { //sourceSets.main.sourceGeneratorsTask.dependsOn xjc //sourceSets.main.sourceGeneratorsTask.dependsOn generateGrammarSource tasks.compile.dependsOn generateGrammarSource + + +tasks."matrix_mariadb" { + beforeTest { descriptor -> + println "Starting test: " + descriptor + } +} \ No newline at end of file diff --git a/hibernate-core/src/test/java/org/hibernate/id/uuid/GeneratedValueTest.java b/hibernate-core/src/test/java/org/hibernate/id/uuid/GeneratedValueTest.java index 10b7f6b073..29e90577c8 100644 --- a/hibernate-core/src/test/java/org/hibernate/id/uuid/GeneratedValueTest.java +++ b/hibernate-core/src/test/java/org/hibernate/id/uuid/GeneratedValueTest.java @@ -7,6 +7,7 @@ package org.hibernate.id.uuid; import java.util.UUID; +import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; @@ -39,7 +40,7 @@ import static org.junit.Assert.assertNotNull; */ public class GeneratedValueTest extends BaseUnitTestCase { @Test - public void testGeneratedUuidId() { + public void testGeneratedUuidId() throws Exception { StandardServiceRegistry ssr = new StandardServiceRegistryBuilder() .applySetting( AvailableSettings.HBM2DDL_AUTO, "create-drop" ) .build(); @@ -73,9 +74,17 @@ public class GeneratedValueTest extends BaseUnitTestCase { s = sf.openSession(); s.beginTransaction(); - s.delete( theEntity ); - s.getTransaction().commit(); - s.close(); + try { + s.delete( theEntity ); + s.getTransaction().commit(); + } + catch (Exception e) { + s.getTransaction().rollback(); + throw e; + } + finally { + s.close(); + } } finally { try { @@ -94,6 +103,7 @@ public class GeneratedValueTest extends BaseUnitTestCase { @Table(name = "TheEntity") public static class TheEntity { @Id + @Column( length = 16 ) @GeneratedValue public UUID id; } diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/loader/LoaderTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/loader/LoaderTest.java index 069867ff77..2e3440d05c 100755 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/loader/LoaderTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/loader/LoaderTest.java @@ -15,6 +15,8 @@ import java.util.Set; import org.hibernate.ObjectNotFoundException; import org.hibernate.Session; import org.hibernate.Transaction; +import org.hibernate.resource.transaction.spi.TransactionStatus; + import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.junit.Test; @@ -39,49 +41,54 @@ public class LoaderTest extends BaseCoreFunctionalTestCase { @Test public void testBasic() throws Exception { + // set up data... Session s = openSession( ); Transaction tx = s.beginTransaction(); Team t = new Team(); Player p = new Player(); - p.setName("me"); - t.getPlayers().add(p); - p.setTeam(t); - + p.setName( "me" ); + t.getPlayers().add( p ); + p.setTeam( t ); + s.persist(p); + s.persist( t ); + tx.commit(); + s.close(); - try { - s.persist(p); - s.persist(t); - tx.commit(); - s.close(); - - s= openSession( ); - tx = s.beginTransaction(); - Team t2 = (Team)s.load(Team.class,new Long(1)); - Set players = t2.getPlayers(); - Iterator iterator = players.iterator(); - assertEquals("me", iterator.next().getName()); - tx.commit(); - - } - catch (Exception e) { - e.printStackTrace(); - if ( tx != null ) tx.rollback(); - } - finally { - s.close(); - } + s = openSession(); + tx = s.beginTransaction(); + Team t2 = s.load( Team.class, t.getId() ); + Set players = t2.getPlayers(); + Iterator iterator = players.iterator(); + assertEquals( "me", iterator.next().getName() ); + tx.commit(); + s.close(); + + // clean up data + s = openSession(); + tx = s.beginTransaction(); + t = s.get( Team.class, t2.getId() ); + p = s.get( Player.class, p.getId() ); + s.delete( p ); + s.delete( t ); + tx.commit(); + s.close(); } @Test public void testGetNotExisting() { Session s = openSession(); + s.beginTransaction(); try { long notExistingId = 1l; s.load( Team.class, notExistingId ); s.get( Team.class, notExistingId ); + s.getTransaction().commit(); } catch (ObjectNotFoundException e) { + if ( s.getTransaction().getStatus() == TransactionStatus.ACTIVE ) { + s.getTransaction().rollback(); + } fail("#get threw an ObjectNotFoundExcepton"); } finally { diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/lob/SerializableToBlobTypeTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/lob/SerializableToBlobTypeTest.java index 4aeb202106..76963e0d5f 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/lob/SerializableToBlobTypeTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/lob/SerializableToBlobTypeTest.java @@ -75,6 +75,7 @@ public class SerializableToBlobTypeTest extends BaseNonConfigCoreFunctionalTestC session.close(); session = openSession(); + session.beginTransaction(); EntitySerialize persistedSerialize = (EntitySerialize) session.get( EntitySerialize.class, entitySerialize.id ); assertEquals( "explicitLob", persistedSerialize.explicitLob.value ); @@ -84,6 +85,9 @@ public class SerializableToBlobTypeTest extends BaseNonConfigCoreFunctionalTestC assertEquals( "defaultExplicitLob", persistedSerialize.explicitLob.defaultValue ); + session.delete( persistedSerialize ); + + session.getTransaction().commit(); session.close(); } diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/onetoone/hhh9798/OneToOneJoinTableTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/onetoone/hhh9798/OneToOneJoinTableTest.java index 347ecf95de..cd4023001f 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/onetoone/hhh9798/OneToOneJoinTableTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/onetoone/hhh9798/OneToOneJoinTableTest.java @@ -14,6 +14,8 @@ import org.junit.Test; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; +import static org.junit.Assert.fail; + @TestForIssue(jiraKey = "HHH-9798") public class OneToOneJoinTableTest extends BaseCoreFunctionalTestCase { @@ -34,14 +36,28 @@ public class OneToOneJoinTableTest extends BaseCoreFunctionalTestCase { session.save( shipment2 ); tx.commit(); + + fail(); } finally { if ( session != null ) { + session.getTransaction().rollback(); session.close(); } + + cleanUpData(); } } + private void cleanUpData() { + Session session = openSession(); + session.beginTransaction(); + session.createQuery( "delete Shipment" ).executeUpdate(); + session.createQuery( "delete Item" ).executeUpdate(); + session.getTransaction().commit(); + session.close(); + } + @Override protected Class[] getAnnotatedClasses() { return new Class[] { diff --git a/hibernate-core/src/test/java/org/hibernate/test/extralazy/ExtraLazyTest.java b/hibernate-core/src/test/java/org/hibernate/test/extralazy/ExtraLazyTest.java index 051b71137c..1b7afddbc6 100755 --- a/hibernate-core/src/test/java/org/hibernate/test/extralazy/ExtraLazyTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/extralazy/ExtraLazyTest.java @@ -17,6 +17,9 @@ import java.util.Map; import org.hibernate.Hibernate; import org.hibernate.Session; import org.hibernate.Transaction; + +import org.hibernate.testing.DialectChecks; +import org.hibernate.testing.RequiresDialectFeature; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.junit.Test; @@ -200,6 +203,7 @@ public class ExtraLazyTest extends BaseCoreFunctionalTestCase { } @Test + @RequiresDialectFeature( DialectChecks.DoubleQuoteQuoting.class ) public void testSQLQuery() { Session s = openSession(); Transaction t = s.beginTransaction(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/hqlfetchscroll/HQLScrollFetchTest.java b/hibernate-core/src/test/java/org/hibernate/test/hqlfetchscroll/HQLScrollFetchTest.java index 6e30356dcb..8bc46bd1ab 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/hqlfetchscroll/HQLScrollFetchTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/hqlfetchscroll/HQLScrollFetchTest.java @@ -44,32 +44,38 @@ public class HQLScrollFetchTest extends BaseCoreFunctionalTestCase { @Test public void testNoScroll() { Session s = openSession(); + s.beginTransaction(); List list = s.createQuery( QUERY ).setResultTransformer( DistinctRootEntityResultTransformer.INSTANCE ).list(); assertResultFromAllUsers( list ); + s.getTransaction().commit(); s.close(); } @Test - @SkipForDialect( { SQLServerDialect.class, Oracle8iDialect.class, H2Dialect.class, DB2Dialect.class, + @SkipForDialect( { SQLServerDialect.class, Oracle8iDialect.class, DB2Dialect.class, AbstractHANADialect.class, TeradataDialect.class } ) public void testScroll() { Session s = openSession(); - ScrollableResults results = s.createQuery( QUERY ).scroll(); + s.beginTransaction(); + ScrollableResults results = s.createQuery( QUERY + " order by p.name asc, c.name asc" ).scroll(); List list = new ArrayList(); while ( results.next() ) { list.add( results.get( 0 ) ); } assertResultFromAllUsers( list ); + s.getTransaction().commit(); s.close(); } @Test public void testIncompleteScrollFirstResult() { Session s = openSession(); + s.beginTransaction(); ScrollableResults results = s.createQuery( QUERY + " order by p.name asc" ).scroll(); results.next(); Parent p = (Parent) results.get( 0 ); assertResultFromOneUser( p ); + s.getTransaction().commit(); s.close(); } @@ -77,6 +83,7 @@ public class HQLScrollFetchTest extends BaseCoreFunctionalTestCase { @TestForIssue( jiraKey = "HHH-1283" ) public void testIncompleteScrollSecondResult() { Session s = openSession(); + s.beginTransaction(); ScrollableResults results = s.createQuery( QUERY + " order by p.name asc" ).scroll(); results.next(); Parent p = (Parent) results.get( 0 ); @@ -84,6 +91,7 @@ public class HQLScrollFetchTest extends BaseCoreFunctionalTestCase { results.next(); p = (Parent) results.get( 0 ); assertResultFromOneUser( p ); + s.getTransaction().commit(); s.close(); } @@ -119,6 +127,7 @@ public class HQLScrollFetchTest extends BaseCoreFunctionalTestCase { @TestForIssue( jiraKey = "HHH-1283") public void testIncompleteScroll() { Session s = openSession(); + s.beginTransaction(); ScrollableResults results = s.createQuery( QUERY + " order by p.name asc" ).scroll(); results.next(); Parent p = (Parent) results.get( 0 ); @@ -151,6 +160,7 @@ public class HQLScrollFetchTest extends BaseCoreFunctionalTestCase { // check that the same second parent is obtained by calling Session.get() assertNull( pOther ); assertNull( cOther ); + s.getTransaction().commit(); s.close(); } @@ -158,6 +168,7 @@ public class HQLScrollFetchTest extends BaseCoreFunctionalTestCase { @TestForIssue( jiraKey = "HHH-1283" ) public void testIncompleteScrollLast() { Session s = openSession(); + s.beginTransaction(); ScrollableResults results = s.createQuery( QUERY + " order by p.name asc" ).scroll(); results.next(); Parent p = (Parent) results.get( 0 ); @@ -193,6 +204,7 @@ public class HQLScrollFetchTest extends BaseCoreFunctionalTestCase { assertTrue( Hibernate.isInitialized( pOther.getChildren() ) ); assertEquals( childrenOther, pOther.getChildren() ); assertResultFromOneUser( pOther ); + s.getTransaction().commit(); s.close(); } @@ -200,12 +212,14 @@ public class HQLScrollFetchTest extends BaseCoreFunctionalTestCase { @TestForIssue( jiraKey = "HHH-1283" ) public void testScrollOrderParentAsc() { Session s = openSession(); + s.beginTransaction(); ScrollableResults results = s.createQuery( QUERY + " order by p.name asc" ).scroll(); List list = new ArrayList(); while ( results.next() ) { list.add( results.get( 0 ) ); } assertResultFromAllUsers( list ); + s.getTransaction().commit(); s.close(); } @@ -213,12 +227,14 @@ public class HQLScrollFetchTest extends BaseCoreFunctionalTestCase { @TestForIssue( jiraKey = "HHH-1283" ) public void testScrollOrderParentDesc() { Session s = openSession(); + s.beginTransaction(); ScrollableResults results = s.createQuery( QUERY + " order by p.name desc" ).scroll(); List list = new ArrayList(); while ( results.next() ) { list.add( results.get( 0 ) ); } assertResultFromAllUsers( list ); + s.getTransaction().commit(); s.close(); } @@ -226,12 +242,14 @@ public class HQLScrollFetchTest extends BaseCoreFunctionalTestCase { @TestForIssue( jiraKey = "HHH-1283" ) public void testScrollOrderParentAscChildrenAsc() { Session s = openSession(); + s.beginTransaction(); ScrollableResults results = s.createQuery( QUERY + " order by p.name asc, c.name asc" ).scroll(); List list = new ArrayList(); while ( results.next() ) { list.add( results.get( 0 ) ); } assertResultFromAllUsers( list ); + s.getTransaction().commit(); s.close(); } @@ -239,12 +257,14 @@ public class HQLScrollFetchTest extends BaseCoreFunctionalTestCase { @TestForIssue( jiraKey = "HHH-1283" ) public void testScrollOrderParentAscChildrenDesc() { Session s = openSession(); + s.beginTransaction(); ScrollableResults results = s.createQuery( QUERY + " order by p.name asc, c.name desc" ).scroll(); List list = new ArrayList(); while ( results.next() ) { list.add( results.get( 0 ) ); } assertResultFromAllUsers( list ); + s.getTransaction().commit(); s.close(); } diff --git a/hibernate-core/src/test/java/org/hibernate/test/jpa/ql/NamedNativeQueryTest.java b/hibernate-core/src/test/java/org/hibernate/test/jpa/ql/NamedNativeQueryTest.java index 4b6a366358..d2ede23b34 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/jpa/ql/NamedNativeQueryTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/jpa/ql/NamedNativeQueryTest.java @@ -203,10 +203,12 @@ public class NamedNativeQueryTest extends BaseCoreFunctionalTestCase { session.close(); session = openSession(); + session.beginTransaction(); DestinationEntity get = (DestinationEntity) session.get( DestinationEntity.class, destinationEntity.id ); assertEquals( anotherFrom, get.from ); assertEquals( inverseFullName, get.fullNameFrom ); + session.getTransaction().commit(); session.close(); } diff --git a/hibernate-core/src/test/java/org/hibernate/test/legacy/MultiTableTest.java b/hibernate-core/src/test/java/org/hibernate/test/legacy/MultiTableTest.java index 25247e03f6..7783cde641 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/legacy/MultiTableTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/legacy/MultiTableTest.java @@ -552,23 +552,44 @@ public class MultiTableTest extends LegacyTestCase { if ( o instanceof Top ) foundSimple++; if ( o instanceof Multi ) foundMulti++; } - assertTrue( foundSimple==2 && foundMulti==1 ); - assertEquals( 3, doDelete( s, "from Top" ) ); + assertTrue( foundSimple == 2 && foundMulti == 1 ); t.commit(); s.close(); + + s = openSession(); + t = s.beginTransaction(); + try { + // MySQL does not like deleting rows that refer to itself without first + // null'ing out the FK. Ugh... + ls = s.load( Lower.class, id ); + ls.setOther( null ); + ls.setAnother( null ); + ls.setYetanother( null ); + for ( Object o : ls.getSet() ) { + s.delete( o ); + } + ls.getSet().clear(); + s.flush(); + s.delete( ls ); + t.commit(); + } + catch (Exception e) { + t.rollback(); + throw e; + } + finally { + s.close(); + } } @Test public void testMultiTableManyToOne() throws Exception { Session s = openSession(); Transaction t = s.beginTransaction(); - assertTrue( s.createQuery( "from Top" ).list().size()==0 ); + assertTrue( s.createQuery( "from Top" ).list().size() == 0 ); Multi multi = new Multi(); - multi.setExtraProp("extra"); + multi.setExtraProp( "extra" ); multi.setName("name"); - Top simp = new Top(); - simp.setDate( new Date() ); - simp.setName("simp"); s.save(multi); Lower ls = new Lower(); ls.setOther(ls); @@ -582,13 +603,28 @@ public class MultiTableTest extends LegacyTestCase { s = openSession(); t = s.beginTransaction(); - ls = (Lower) s.load(Lower.class, id); - assertTrue( ls.getOther()==ls && ls.getYetanother()==ls ); - assertTrue( ls.getAnother().getName().equals("name") && ls.getAnother() instanceof Multi ); - s.delete(ls); - s.delete( ls.getAnother() ); - t.commit(); - s.close(); + try { + // MySQL does not like deleting rows that refer to itself without first + // null'ing out the FK. Ugh... + ls = s.load( Lower.class, id ); + assertTrue( ls.getOther() == ls && ls.getYetanother() == ls ); + assertTrue( ls.getAnother().getName().equals( "name" ) && ls.getAnother() instanceof Multi ); + s.delete( ls.getAnother() ); + ls.setOther( null ); + ls.setAnother( null ); + ls.setYetanother( null ); + ls.getSet().clear(); + s.flush(); + s.delete( ls ); + t.commit(); + } + catch (Exception e) { + t.rollback(); + throw e; + } + finally { + s.close(); + } } @Test diff --git a/hibernate-core/src/test/java/org/hibernate/test/naturalid/mutable/cached/CachedMutableNaturalIdTest.java b/hibernate-core/src/test/java/org/hibernate/test/naturalid/mutable/cached/CachedMutableNaturalIdTest.java index 308dfc4338..49735d8662 100755 --- a/hibernate-core/src/test/java/org/hibernate/test/naturalid/mutable/cached/CachedMutableNaturalIdTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/naturalid/mutable/cached/CachedMutableNaturalIdTest.java @@ -49,7 +49,7 @@ public abstract class CachedMutableNaturalIdTest extends BaseCoreFunctionalTestC session = openSession(); session.beginTransaction(); - it = (Another) session.bySimpleNaturalId( Another.class ).load( "it" ); + it = session.bySimpleNaturalId( Another.class ).load( "it" ); assertNotNull( it ); // change it's name it.setName( "it2" ); @@ -58,9 +58,9 @@ public abstract class CachedMutableNaturalIdTest extends BaseCoreFunctionalTestC session = openSession(); session.beginTransaction(); - it = (Another) session.bySimpleNaturalId( Another.class ).load( "it" ); + it = session.bySimpleNaturalId( Another.class ).load( "it" ); assertNull( it ); - it = (Another) session.bySimpleNaturalId( Another.class ).load( "it2" ); + it = session.bySimpleNaturalId( Another.class ).load( "it2" ); assertNotNull( it ); session.delete( it ); session.getTransaction().commit(); @@ -78,7 +78,7 @@ public abstract class CachedMutableNaturalIdTest extends BaseCoreFunctionalTestC session = openSession(); session.beginTransaction(); - it = (Another) session.bySimpleNaturalId( Another.class ).load( "it" ); + it = session.bySimpleNaturalId( Another.class ).load( "it" ); assertNotNull( it ); session.getTransaction().commit(); session.close(); @@ -93,9 +93,9 @@ public abstract class CachedMutableNaturalIdTest extends BaseCoreFunctionalTestC session = openSession(); session.beginTransaction(); - it = (Another) session.bySimpleNaturalId( Another.class ).load( "it" ); + it = session.bySimpleNaturalId( Another.class ).load( "it" ); assertNull( it ); - it = (Another) session.bySimpleNaturalId( Another.class ).load( "it2" ); + it = session.bySimpleNaturalId( Another.class ).load( "it2" ); assertNotNull( it ); session.delete( it ); session.getTransaction().commit(); @@ -118,7 +118,7 @@ public abstract class CachedMutableNaturalIdTest extends BaseCoreFunctionalTestC session = openSession(); for (int i=0; i < 10; i++) { session.beginTransaction(); - it = (Another) session.byId(Another.class).load(id); + it = session.byId(Another.class).load(id); if (i == 9) { it.setName("name" + i); } @@ -128,15 +128,16 @@ public abstract class CachedMutableNaturalIdTest extends BaseCoreFunctionalTestC session = openSession(); session.beginTransaction(); - it = (Another) session.bySimpleNaturalId(Another.class).load("it"); + it = session.bySimpleNaturalId(Another.class).load("it"); assertNull(it); - assertEquals(0, session.getSessionFactory().getStatistics().getNaturalIdCacheHitCount()); - it = (Another) session.byId(Another.class).load(id); + assertEquals( 0, session.getSessionFactory().getStatistics().getNaturalIdCacheHitCount() ); + it = session.byId(Another.class).load(id); session.delete(it); session.getTransaction().commit(); + session.close(); // finally there should be only 2 NaturalIdCache puts : 1. insertion, 2. when updating natural-id from 'it' to 'name9' - assertEquals(2, session.getSessionFactory().getStatistics().getNaturalIdCachePutCount()); + assertEquals( 2, session.getSessionFactory().getStatistics().getNaturalIdCachePutCount() ); } @Test @@ -153,7 +154,7 @@ public abstract class CachedMutableNaturalIdTest extends BaseCoreFunctionalTestC session = openSession(); session.beginTransaction(); - it = (AllCached) session.byId( AllCached.class ).load( id ); + it = session.byId( AllCached.class ).load( id ); it.setName( "it2" ); it = (AllCached) session.bySimpleNaturalId( AllCached.class ).load( "it" ); @@ -177,19 +178,22 @@ public abstract class CachedMutableNaturalIdTest extends BaseCoreFunctionalTestC b.assA = a; a.assB.add( b ); session.getTransaction().commit(); - session.clear(); + session.close(); + + session = openSession(); session.beginTransaction(); - session.buildLockRequest(LockOptions.NONE).lock(b); // HHH-7513 failure during reattachment - session.delete(b.assA); - session.delete(b); - - session.getTransaction().commit(); - session.clear(); - + session.buildLockRequest(LockOptions.NONE).lock( b ); // HHH-7513 failure during reattachment + session.delete( b.assA ); + session.delete( b ); + session.flush(); + // true if the re-attachment worked assertEquals( session.createQuery( "FROM A" ).list().size(), 0 ); assertEquals( session.createQuery( "FROM B" ).list().size(), 0 ); + + session.getTransaction().commit(); + session.close(); } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/proxy/narrow/ProxyNarrowingTest.java b/hibernate-core/src/test/java/org/hibernate/test/proxy/narrow/ProxyNarrowingTest.java index c69a6025ed..c3f23b4e69 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/proxy/narrow/ProxyNarrowingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/proxy/narrow/ProxyNarrowingTest.java @@ -54,9 +54,11 @@ public class ProxyNarrowingTest extends BaseCoreFunctionalTestCase { session = openSession(); try { + session.beginTransaction(); + // load a proxified version of the entity into the session: the proxy is based on the AbstractEntity class // as the reference class property is of type AbstractEntity. - LazyAbstractEntityReference reference = (LazyAbstractEntityReference) session.get( LazyAbstractEntityReference.class, entityReferenceId ); + LazyAbstractEntityReference reference = session.get( LazyAbstractEntityReference.class, entityReferenceId ); AbstractEntity abstractEntityProxy = reference.getEntity(); assertTrue( ( abstractEntityProxy instanceof HibernateProxy ) && !Hibernate.isInitialized( abstractEntityProxy ) ); @@ -64,11 +66,18 @@ public class ProxyNarrowingTest extends BaseCoreFunctionalTestCase { assertTrue( Hibernate.isInitialized( abstractEntityProxy ) ); // load the concrete class via session.load to trigger the StatefulPersistenceContext.narrowProxy code - ConcreteEntity concreteEntityProxy = (ConcreteEntity) session.load( ConcreteEntity.class, abstractEntityProxy.getId() ); + ConcreteEntity concreteEntityProxy = session.load( ConcreteEntity.class, abstractEntityProxy.getId() ); // the new proxy created should be initialized assertTrue( Hibernate.isInitialized( concreteEntityProxy ) ); assertTrue( session.contains( concreteEntityProxy ) ); + + + // clean up + session.delete( reference ); + session.delete( concreteEntityProxy ); + + session.getTransaction().commit(); } finally { session.close(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/quote/QuoteTest.java b/hibernate-core/src/test/java/org/hibernate/test/quote/QuoteTest.java index 99702f4c19..60878de45c 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/quote/QuoteTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/quote/QuoteTest.java @@ -38,8 +38,11 @@ public class QuoteTest extends BaseNonConfigCoreFunctionalTestCase { @Test public void testQuoteManytoMany() { + String role = User.class.getName() + ".roles"; + assertEquals( "User_Role", metadata().getCollectionBinding( role ).getCollectionTable().getName() ); + Session s = openSession(); - Transaction tx = s.beginTransaction(); + s.beginTransaction(); User u = new User(); s.persist( u ); Role r = new Role(); @@ -47,11 +50,9 @@ public class QuoteTest extends BaseNonConfigCoreFunctionalTestCase { u.getRoles().add( r ); s.flush(); s.clear(); - u = (User) s.get( User.class, u.getId() ); + u = s.get( User.class, u.getId() ); assertEquals( 1, u.getRoles().size() ); - tx.rollback(); - String role = User.class.getName() + ".roles"; - assertEquals( "User_Role", metadata().getCollectionBinding( role ).getCollectionTable().getName() ); + s.getTransaction().rollback(); s.close(); } @@ -66,11 +67,11 @@ public class QuoteTest extends BaseNonConfigCoreFunctionalTestCase { s.persist( house ); s.persist( user ); s.getTransaction().commit(); - s.clear(); + s.close(); s = openSession(); s.getTransaction().begin(); - user = (User) s.get( User.class, user.getId() ); + user = s.get( User.class, user.getId() ); assertNotNull( user ); assertNotNull( user.getHouse() ); // seems trivial, but if quoting normalization worked on the join column, these should all be the same @@ -98,12 +99,28 @@ public class QuoteTest extends BaseNonConfigCoreFunctionalTestCase { s.persist( container2 ); s.persist( container1 ); s.getTransaction().commit(); - s.clear(); - - Container result = (Container) s.get( Container.class, container1.id ); + s.close(); + + s = openSession(); + s.beginTransaction(); + Container result = s.get( Container.class, container1.id ); assertNotNull( result ); assertNotNull( result.items ); assertEquals( 2, result.items.size() ); + s.getTransaction().commit(); + s.close(); + + s = openSession(); + s.beginTransaction(); + container1 = s.get( Container.class, container1.id ); + for ( Item item : container1.items ) { + item.parent = null; + } + container1.items.clear(); + s.flush(); + s.createQuery( "delete Item" ).executeUpdate(); + s.getTransaction().commit(); + s.close(); } @Override @@ -118,7 +135,7 @@ public class QuoteTest extends BaseNonConfigCoreFunctionalTestCase { }; } - @Entity + @Entity( name = "Item" ) @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) private static abstract class Item { diff --git a/hibernate-core/src/test/java/org/hibernate/test/subselect/CompositeIdTypeBindingTest.java b/hibernate-core/src/test/java/org/hibernate/test/subselect/CompositeIdTypeBindingTest.java index 75c4b729e4..182ccf812b 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/subselect/CompositeIdTypeBindingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/subselect/CompositeIdTypeBindingTest.java @@ -9,7 +9,7 @@ package org.hibernate.test.subselect; import java.util.ArrayList; import java.util.List; -import junit.framework.Assert; +import org.junit.Assert; import org.hibernate.Session; import org.hibernate.dialect.H2Dialect; @@ -37,6 +37,8 @@ public class CompositeIdTypeBindingTest extends BaseCoreFunctionalTestCase { @Test public void testCompositeTypeBinding() { + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // prepare test data Session session = openSession(); session.beginTransaction(); @@ -45,18 +47,18 @@ public class CompositeIdTypeBindingTest extends BaseCoreFunctionalTestCase { employeegroup.addEmployee( new Employee( "david" ) ); session.save( employeegroup ); - employeegroup = new EmployeeGroup( new EmployeeGroupId( "c", "d" ) ); employeegroup.addEmployee( new Employee( "gail" ) ); employeegroup.addEmployee( new Employee( "steve" ) ); session.save( employeegroup ); - session.getTransaction().commit(); - session.close(); + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // Perform the test session = openSession(); + session.beginTransaction(); List parameters = new ArrayList(); parameters.add( new EmployeeGroupId( "a", "b" ) ); @@ -73,6 +75,22 @@ public class CompositeIdTypeBindingTest extends BaseCoreFunctionalTestCase { Assert.assertEquals( "a", employeegroup.getId().getGroupName() ); Assert.assertNotNull( employeegroup.getEmployees() ); Assert.assertEquals( 2, employeegroup.getEmployees().size() ); + session.getTransaction().commit(); + session.close(); + + + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // clean up test data + session = openSession(); + session.beginTransaction(); + List egs = session.createQuery( "from EmployeeGroup" ).list(); + for ( EmployeeGroup eg : egs ) { + eg.getEmployees().clear(); + } + session.flush(); + session.createQuery( "delete from EmployeeGroup" ).executeUpdate(); + session.createQuery( "delete from Employee" ).executeUpdate(); + session.getTransaction().commit(); session.close(); } } diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/DialectChecks.java b/hibernate-testing/src/main/java/org/hibernate/testing/DialectChecks.java index 096ba07467..1256603e2c 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/DialectChecks.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/DialectChecks.java @@ -158,4 +158,11 @@ abstract public class DialectChecks { return dialect.supportsLockTimeouts(); } } + + public static class DoubleQuoteQuoting implements DialectCheck { + @Override + public boolean isMatch(Dialect dialect) { + return '\"' == dialect.openQuote() && '\"' == dialect.closeQuote(); + } + } } diff --git a/working-5.0-migration-guide.md b/working-5.0-migration-guide.md index 12bc3fea81..222765e868 100644 --- a/working-5.0-migration-guide.md +++ b/working-5.0-migration-guide.md @@ -33,6 +33,8 @@ Working list of changes for 5.0 * Valid `hibernate.cache.default_cache_concurrency_strategy` setting values are now defined via `org.hibernate.cache.spi.access.AccessType#getExternalName` rather than the `org.hibernate.cache.spi.access.AccessType` enum names; this is more consistent with other Hibernate settings +* For ids defined as UUID with generation, for some databases it is required to explicitly set the `@Column( length=16 )` + in order to generate BINARY(16) so that comparisons properly work. TODOs =====