HHH-9930 - Enable mariadb (mysql) database profile

This commit is contained in:
Steve Ebersole 2015-07-20 12:06:09 -05:00
parent 4a2512e099
commit b24ba54d38
17 changed files with 252 additions and 87 deletions

View File

@ -137,6 +137,8 @@ subprojects { subProject ->
testRuntime( libraries.h2 ) testRuntime( libraries.h2 )
testRuntime( libraries.woodstox ) testRuntime( libraries.woodstox )
testRuntime( 'org.mariadb.jdbc:mariadb-java-client:1.1.7' )
// 6.6 gave me some NPE problems from within checkstyle... // 6.6 gave me some NPE problems from within checkstyle...
checkstyle 'com.puppycrawl.tools:checkstyle:6.5' checkstyle 'com.puppycrawl.tools:checkstyle:6.5'
} }
@ -189,9 +191,9 @@ subprojects { subProject ->
systemProperties['hibernate.test.validatefailureexpected'] = true systemProperties['hibernate.test.validatefailureexpected'] = true
systemProperties += System.properties.findAll { it.key.startsWith( "hibernate.") } systemProperties += System.properties.findAll { it.key.startsWith( "hibernate.") }
// beforeTest { descriptor -> beforeTest { descriptor ->
// println "Starting test: " + descriptor println "Starting test: " + descriptor
// } }
// afterTest { descriptor -> // afterTest { descriptor ->
// println "Completed test: " + descriptor // println "Completed test: " + descriptor

View File

@ -5,7 +5,7 @@
# See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. # See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
# #
hibernate.dialect = hibernate.dialect org.hibernate.dialect.MySQL5Dialect
hibernate.connection.driver_class org.mariadb.jdbc.Driver hibernate.connection.driver_class org.mariadb.jdbc.Driver
hibernate.connection.url jdbc:mariadb://localhost/hibernate_orm_test hibernate.connection.url jdbc:mariadb://localhost/hibernate_orm_test
hibernate.connection.username hibernate_orm_test hibernate.connection.username hibernate_orm_test

View File

@ -134,3 +134,10 @@ xjc {
//sourceSets.main.sourceGeneratorsTask.dependsOn xjc //sourceSets.main.sourceGeneratorsTask.dependsOn xjc
//sourceSets.main.sourceGeneratorsTask.dependsOn generateGrammarSource //sourceSets.main.sourceGeneratorsTask.dependsOn generateGrammarSource
tasks.compile.dependsOn generateGrammarSource tasks.compile.dependsOn generateGrammarSource
tasks."matrix_mariadb" {
beforeTest { descriptor ->
println "Starting test: " + descriptor
}
}

View File

@ -7,6 +7,7 @@
package org.hibernate.id.uuid; package org.hibernate.id.uuid;
import java.util.UUID; import java.util.UUID;
import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.GeneratedValue; import javax.persistence.GeneratedValue;
import javax.persistence.Id; import javax.persistence.Id;
@ -39,7 +40,7 @@ import static org.junit.Assert.assertNotNull;
*/ */
public class GeneratedValueTest extends BaseUnitTestCase { public class GeneratedValueTest extends BaseUnitTestCase {
@Test @Test
public void testGeneratedUuidId() { public void testGeneratedUuidId() throws Exception {
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder() StandardServiceRegistry ssr = new StandardServiceRegistryBuilder()
.applySetting( AvailableSettings.HBM2DDL_AUTO, "create-drop" ) .applySetting( AvailableSettings.HBM2DDL_AUTO, "create-drop" )
.build(); .build();
@ -73,9 +74,17 @@ public class GeneratedValueTest extends BaseUnitTestCase {
s = sf.openSession(); s = sf.openSession();
s.beginTransaction(); s.beginTransaction();
s.delete( theEntity ); try {
s.getTransaction().commit(); s.delete( theEntity );
s.close(); s.getTransaction().commit();
}
catch (Exception e) {
s.getTransaction().rollback();
throw e;
}
finally {
s.close();
}
} }
finally { finally {
try { try {
@ -94,6 +103,7 @@ public class GeneratedValueTest extends BaseUnitTestCase {
@Table(name = "TheEntity") @Table(name = "TheEntity")
public static class TheEntity { public static class TheEntity {
@Id @Id
@Column( length = 16 )
@GeneratedValue @GeneratedValue
public UUID id; public UUID id;
} }

View File

@ -15,6 +15,8 @@ import java.util.Set;
import org.hibernate.ObjectNotFoundException; import org.hibernate.ObjectNotFoundException;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.Transaction; import org.hibernate.Transaction;
import org.hibernate.resource.transaction.spi.TransactionStatus;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test; import org.junit.Test;
@ -39,49 +41,54 @@ public class LoaderTest extends BaseCoreFunctionalTestCase {
@Test @Test
public void testBasic() throws Exception { public void testBasic() throws Exception {
// set up data...
Session s = openSession( ); Session s = openSession( );
Transaction tx = s.beginTransaction(); Transaction tx = s.beginTransaction();
Team t = new Team(); Team t = new Team();
Player p = new Player(); Player p = new Player();
p.setName("me"); p.setName( "me" );
t.getPlayers().add(p); t.getPlayers().add( p );
p.setTeam(t); p.setTeam( t );
s.persist(p);
s.persist( t );
tx.commit();
s.close();
try { s = openSession();
s.persist(p); tx = s.beginTransaction();
s.persist(t); Team t2 = s.load( Team.class, t.getId() );
tx.commit(); Set<Player> players = t2.getPlayers();
s.close(); Iterator<Player> iterator = players.iterator();
assertEquals( "me", iterator.next().getName() );
s= openSession( ); tx.commit();
tx = s.beginTransaction(); s.close();
Team t2 = (Team)s.load(Team.class,new Long(1));
Set<Player> players = t2.getPlayers(); // clean up data
Iterator<Player> iterator = players.iterator(); s = openSession();
assertEquals("me", iterator.next().getName()); tx = s.beginTransaction();
tx.commit(); t = s.get( Team.class, t2.getId() );
p = s.get( Player.class, p.getId() );
} s.delete( p );
catch (Exception e) { s.delete( t );
e.printStackTrace(); tx.commit();
if ( tx != null ) tx.rollback(); s.close();
}
finally {
s.close();
}
} }
@Test @Test
public void testGetNotExisting() { public void testGetNotExisting() {
Session s = openSession(); Session s = openSession();
s.beginTransaction();
try { try {
long notExistingId = 1l; long notExistingId = 1l;
s.load( Team.class, notExistingId ); s.load( Team.class, notExistingId );
s.get( Team.class, notExistingId ); s.get( Team.class, notExistingId );
s.getTransaction().commit();
} }
catch (ObjectNotFoundException e) { catch (ObjectNotFoundException e) {
if ( s.getTransaction().getStatus() == TransactionStatus.ACTIVE ) {
s.getTransaction().rollback();
}
fail("#get threw an ObjectNotFoundExcepton"); fail("#get threw an ObjectNotFoundExcepton");
} }
finally { finally {

View File

@ -75,6 +75,7 @@ public class SerializableToBlobTypeTest extends BaseNonConfigCoreFunctionalTestC
session.close(); session.close();
session = openSession(); session = openSession();
session.beginTransaction();
EntitySerialize persistedSerialize = (EntitySerialize) session.get( EntitySerialize.class, entitySerialize.id ); EntitySerialize persistedSerialize = (EntitySerialize) session.get( EntitySerialize.class, entitySerialize.id );
assertEquals( "explicitLob", persistedSerialize.explicitLob.value ); assertEquals( "explicitLob", persistedSerialize.explicitLob.value );
@ -84,6 +85,9 @@ public class SerializableToBlobTypeTest extends BaseNonConfigCoreFunctionalTestC
assertEquals( "defaultExplicitLob", persistedSerialize.explicitLob.defaultValue ); assertEquals( "defaultExplicitLob", persistedSerialize.explicitLob.defaultValue );
session.delete( persistedSerialize );
session.getTransaction().commit();
session.close(); session.close();
} }

View File

@ -14,6 +14,8 @@ import org.junit.Test;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import static org.junit.Assert.fail;
@TestForIssue(jiraKey = "HHH-9798") @TestForIssue(jiraKey = "HHH-9798")
public class OneToOneJoinTableTest extends BaseCoreFunctionalTestCase { public class OneToOneJoinTableTest extends BaseCoreFunctionalTestCase {
@ -34,14 +36,28 @@ public class OneToOneJoinTableTest extends BaseCoreFunctionalTestCase {
session.save( shipment2 ); session.save( shipment2 );
tx.commit(); tx.commit();
fail();
} }
finally { finally {
if ( session != null ) { if ( session != null ) {
session.getTransaction().rollback();
session.close(); 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 @Override
protected Class<?>[] getAnnotatedClasses() { protected Class<?>[] getAnnotatedClasses() {
return new Class<?>[] { return new Class<?>[] {

View File

@ -17,6 +17,9 @@ import java.util.Map;
import org.hibernate.Hibernate; import org.hibernate.Hibernate;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.Transaction; import org.hibernate.Transaction;
import org.hibernate.testing.DialectChecks;
import org.hibernate.testing.RequiresDialectFeature;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test; import org.junit.Test;
@ -200,6 +203,7 @@ public class ExtraLazyTest extends BaseCoreFunctionalTestCase {
} }
@Test @Test
@RequiresDialectFeature( DialectChecks.DoubleQuoteQuoting.class )
public void testSQLQuery() { public void testSQLQuery() {
Session s = openSession(); Session s = openSession();
Transaction t = s.beginTransaction(); Transaction t = s.beginTransaction();

View File

@ -44,32 +44,38 @@ public class HQLScrollFetchTest extends BaseCoreFunctionalTestCase {
@Test @Test
public void testNoScroll() { public void testNoScroll() {
Session s = openSession(); Session s = openSession();
s.beginTransaction();
List list = s.createQuery( QUERY ).setResultTransformer( DistinctRootEntityResultTransformer.INSTANCE ).list(); List list = s.createQuery( QUERY ).setResultTransformer( DistinctRootEntityResultTransformer.INSTANCE ).list();
assertResultFromAllUsers( list ); assertResultFromAllUsers( list );
s.getTransaction().commit();
s.close(); s.close();
} }
@Test @Test
@SkipForDialect( { SQLServerDialect.class, Oracle8iDialect.class, H2Dialect.class, DB2Dialect.class, @SkipForDialect( { SQLServerDialect.class, Oracle8iDialect.class, DB2Dialect.class,
AbstractHANADialect.class, TeradataDialect.class } ) AbstractHANADialect.class, TeradataDialect.class } )
public void testScroll() { public void testScroll() {
Session s = openSession(); 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(); List list = new ArrayList();
while ( results.next() ) { while ( results.next() ) {
list.add( results.get( 0 ) ); list.add( results.get( 0 ) );
} }
assertResultFromAllUsers( list ); assertResultFromAllUsers( list );
s.getTransaction().commit();
s.close(); s.close();
} }
@Test @Test
public void testIncompleteScrollFirstResult() { public void testIncompleteScrollFirstResult() {
Session s = openSession(); Session s = openSession();
s.beginTransaction();
ScrollableResults results = s.createQuery( QUERY + " order by p.name asc" ).scroll(); ScrollableResults results = s.createQuery( QUERY + " order by p.name asc" ).scroll();
results.next(); results.next();
Parent p = (Parent) results.get( 0 ); Parent p = (Parent) results.get( 0 );
assertResultFromOneUser( p ); assertResultFromOneUser( p );
s.getTransaction().commit();
s.close(); s.close();
} }
@ -77,6 +83,7 @@ public class HQLScrollFetchTest extends BaseCoreFunctionalTestCase {
@TestForIssue( jiraKey = "HHH-1283" ) @TestForIssue( jiraKey = "HHH-1283" )
public void testIncompleteScrollSecondResult() { public void testIncompleteScrollSecondResult() {
Session s = openSession(); Session s = openSession();
s.beginTransaction();
ScrollableResults results = s.createQuery( QUERY + " order by p.name asc" ).scroll(); ScrollableResults results = s.createQuery( QUERY + " order by p.name asc" ).scroll();
results.next(); results.next();
Parent p = (Parent) results.get( 0 ); Parent p = (Parent) results.get( 0 );
@ -84,6 +91,7 @@ public class HQLScrollFetchTest extends BaseCoreFunctionalTestCase {
results.next(); results.next();
p = (Parent) results.get( 0 ); p = (Parent) results.get( 0 );
assertResultFromOneUser( p ); assertResultFromOneUser( p );
s.getTransaction().commit();
s.close(); s.close();
} }
@ -119,6 +127,7 @@ public class HQLScrollFetchTest extends BaseCoreFunctionalTestCase {
@TestForIssue( jiraKey = "HHH-1283") @TestForIssue( jiraKey = "HHH-1283")
public void testIncompleteScroll() { public void testIncompleteScroll() {
Session s = openSession(); Session s = openSession();
s.beginTransaction();
ScrollableResults results = s.createQuery( QUERY + " order by p.name asc" ).scroll(); ScrollableResults results = s.createQuery( QUERY + " order by p.name asc" ).scroll();
results.next(); results.next();
Parent p = (Parent) results.get( 0 ); 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() // check that the same second parent is obtained by calling Session.get()
assertNull( pOther ); assertNull( pOther );
assertNull( cOther ); assertNull( cOther );
s.getTransaction().commit();
s.close(); s.close();
} }
@ -158,6 +168,7 @@ public class HQLScrollFetchTest extends BaseCoreFunctionalTestCase {
@TestForIssue( jiraKey = "HHH-1283" ) @TestForIssue( jiraKey = "HHH-1283" )
public void testIncompleteScrollLast() { public void testIncompleteScrollLast() {
Session s = openSession(); Session s = openSession();
s.beginTransaction();
ScrollableResults results = s.createQuery( QUERY + " order by p.name asc" ).scroll(); ScrollableResults results = s.createQuery( QUERY + " order by p.name asc" ).scroll();
results.next(); results.next();
Parent p = (Parent) results.get( 0 ); Parent p = (Parent) results.get( 0 );
@ -193,6 +204,7 @@ public class HQLScrollFetchTest extends BaseCoreFunctionalTestCase {
assertTrue( Hibernate.isInitialized( pOther.getChildren() ) ); assertTrue( Hibernate.isInitialized( pOther.getChildren() ) );
assertEquals( childrenOther, pOther.getChildren() ); assertEquals( childrenOther, pOther.getChildren() );
assertResultFromOneUser( pOther ); assertResultFromOneUser( pOther );
s.getTransaction().commit();
s.close(); s.close();
} }
@ -200,12 +212,14 @@ public class HQLScrollFetchTest extends BaseCoreFunctionalTestCase {
@TestForIssue( jiraKey = "HHH-1283" ) @TestForIssue( jiraKey = "HHH-1283" )
public void testScrollOrderParentAsc() { public void testScrollOrderParentAsc() {
Session s = openSession(); Session s = openSession();
s.beginTransaction();
ScrollableResults results = s.createQuery( QUERY + " order by p.name asc" ).scroll(); ScrollableResults results = s.createQuery( QUERY + " order by p.name asc" ).scroll();
List list = new ArrayList(); List list = new ArrayList();
while ( results.next() ) { while ( results.next() ) {
list.add( results.get( 0 ) ); list.add( results.get( 0 ) );
} }
assertResultFromAllUsers( list ); assertResultFromAllUsers( list );
s.getTransaction().commit();
s.close(); s.close();
} }
@ -213,12 +227,14 @@ public class HQLScrollFetchTest extends BaseCoreFunctionalTestCase {
@TestForIssue( jiraKey = "HHH-1283" ) @TestForIssue( jiraKey = "HHH-1283" )
public void testScrollOrderParentDesc() { public void testScrollOrderParentDesc() {
Session s = openSession(); Session s = openSession();
s.beginTransaction();
ScrollableResults results = s.createQuery( QUERY + " order by p.name desc" ).scroll(); ScrollableResults results = s.createQuery( QUERY + " order by p.name desc" ).scroll();
List list = new ArrayList(); List list = new ArrayList();
while ( results.next() ) { while ( results.next() ) {
list.add( results.get( 0 ) ); list.add( results.get( 0 ) );
} }
assertResultFromAllUsers( list ); assertResultFromAllUsers( list );
s.getTransaction().commit();
s.close(); s.close();
} }
@ -226,12 +242,14 @@ public class HQLScrollFetchTest extends BaseCoreFunctionalTestCase {
@TestForIssue( jiraKey = "HHH-1283" ) @TestForIssue( jiraKey = "HHH-1283" )
public void testScrollOrderParentAscChildrenAsc() { public void testScrollOrderParentAscChildrenAsc() {
Session s = openSession(); Session s = openSession();
s.beginTransaction();
ScrollableResults results = s.createQuery( QUERY + " order by p.name asc, c.name asc" ).scroll(); ScrollableResults results = s.createQuery( QUERY + " order by p.name asc, c.name asc" ).scroll();
List list = new ArrayList(); List list = new ArrayList();
while ( results.next() ) { while ( results.next() ) {
list.add( results.get( 0 ) ); list.add( results.get( 0 ) );
} }
assertResultFromAllUsers( list ); assertResultFromAllUsers( list );
s.getTransaction().commit();
s.close(); s.close();
} }
@ -239,12 +257,14 @@ public class HQLScrollFetchTest extends BaseCoreFunctionalTestCase {
@TestForIssue( jiraKey = "HHH-1283" ) @TestForIssue( jiraKey = "HHH-1283" )
public void testScrollOrderParentAscChildrenDesc() { public void testScrollOrderParentAscChildrenDesc() {
Session s = openSession(); Session s = openSession();
s.beginTransaction();
ScrollableResults results = s.createQuery( QUERY + " order by p.name asc, c.name desc" ).scroll(); ScrollableResults results = s.createQuery( QUERY + " order by p.name asc, c.name desc" ).scroll();
List list = new ArrayList(); List list = new ArrayList();
while ( results.next() ) { while ( results.next() ) {
list.add( results.get( 0 ) ); list.add( results.get( 0 ) );
} }
assertResultFromAllUsers( list ); assertResultFromAllUsers( list );
s.getTransaction().commit();
s.close(); s.close();
} }

View File

@ -203,10 +203,12 @@ public class NamedNativeQueryTest extends BaseCoreFunctionalTestCase {
session.close(); session.close();
session = openSession(); session = openSession();
session.beginTransaction();
DestinationEntity get = (DestinationEntity) session.get( DestinationEntity.class, destinationEntity.id ); DestinationEntity get = (DestinationEntity) session.get( DestinationEntity.class, destinationEntity.id );
assertEquals( anotherFrom, get.from ); assertEquals( anotherFrom, get.from );
assertEquals( inverseFullName, get.fullNameFrom ); assertEquals( inverseFullName, get.fullNameFrom );
session.getTransaction().commit();
session.close(); session.close();
} }

View File

@ -552,23 +552,44 @@ public class MultiTableTest extends LegacyTestCase {
if ( o instanceof Top ) foundSimple++; if ( o instanceof Top ) foundSimple++;
if ( o instanceof Multi ) foundMulti++; if ( o instanceof Multi ) foundMulti++;
} }
assertTrue( foundSimple==2 && foundMulti==1 ); assertTrue( foundSimple == 2 && foundMulti == 1 );
assertEquals( 3, doDelete( s, "from Top" ) );
t.commit(); t.commit();
s.close(); 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 @Test
public void testMultiTableManyToOne() throws Exception { public void testMultiTableManyToOne() throws Exception {
Session s = openSession(); Session s = openSession();
Transaction t = s.beginTransaction(); 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 multi = new Multi();
multi.setExtraProp("extra"); multi.setExtraProp( "extra" );
multi.setName("name"); multi.setName("name");
Top simp = new Top();
simp.setDate( new Date() );
simp.setName("simp");
s.save(multi); s.save(multi);
Lower ls = new Lower(); Lower ls = new Lower();
ls.setOther(ls); ls.setOther(ls);
@ -582,13 +603,28 @@ public class MultiTableTest extends LegacyTestCase {
s = openSession(); s = openSession();
t = s.beginTransaction(); t = s.beginTransaction();
ls = (Lower) s.load(Lower.class, id); try {
assertTrue( ls.getOther()==ls && ls.getYetanother()==ls ); // MySQL does not like deleting rows that refer to itself without first
assertTrue( ls.getAnother().getName().equals("name") && ls.getAnother() instanceof Multi ); // null'ing out the FK. Ugh...
s.delete(ls); ls = s.load( Lower.class, id );
s.delete( ls.getAnother() ); assertTrue( ls.getOther() == ls && ls.getYetanother() == ls );
t.commit(); assertTrue( ls.getAnother().getName().equals( "name" ) && ls.getAnother() instanceof Multi );
s.close(); 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 @Test

View File

@ -49,7 +49,7 @@ public abstract class CachedMutableNaturalIdTest extends BaseCoreFunctionalTestC
session = openSession(); session = openSession();
session.beginTransaction(); session.beginTransaction();
it = (Another) session.bySimpleNaturalId( Another.class ).load( "it" ); it = session.bySimpleNaturalId( Another.class ).load( "it" );
assertNotNull( it ); assertNotNull( it );
// change it's name // change it's name
it.setName( "it2" ); it.setName( "it2" );
@ -58,9 +58,9 @@ public abstract class CachedMutableNaturalIdTest extends BaseCoreFunctionalTestC
session = openSession(); session = openSession();
session.beginTransaction(); session.beginTransaction();
it = (Another) session.bySimpleNaturalId( Another.class ).load( "it" ); it = session.bySimpleNaturalId( Another.class ).load( "it" );
assertNull( it ); assertNull( it );
it = (Another) session.bySimpleNaturalId( Another.class ).load( "it2" ); it = session.bySimpleNaturalId( Another.class ).load( "it2" );
assertNotNull( it ); assertNotNull( it );
session.delete( it ); session.delete( it );
session.getTransaction().commit(); session.getTransaction().commit();
@ -78,7 +78,7 @@ public abstract class CachedMutableNaturalIdTest extends BaseCoreFunctionalTestC
session = openSession(); session = openSession();
session.beginTransaction(); session.beginTransaction();
it = (Another) session.bySimpleNaturalId( Another.class ).load( "it" ); it = session.bySimpleNaturalId( Another.class ).load( "it" );
assertNotNull( it ); assertNotNull( it );
session.getTransaction().commit(); session.getTransaction().commit();
session.close(); session.close();
@ -93,9 +93,9 @@ public abstract class CachedMutableNaturalIdTest extends BaseCoreFunctionalTestC
session = openSession(); session = openSession();
session.beginTransaction(); session.beginTransaction();
it = (Another) session.bySimpleNaturalId( Another.class ).load( "it" ); it = session.bySimpleNaturalId( Another.class ).load( "it" );
assertNull( it ); assertNull( it );
it = (Another) session.bySimpleNaturalId( Another.class ).load( "it2" ); it = session.bySimpleNaturalId( Another.class ).load( "it2" );
assertNotNull( it ); assertNotNull( it );
session.delete( it ); session.delete( it );
session.getTransaction().commit(); session.getTransaction().commit();
@ -118,7 +118,7 @@ public abstract class CachedMutableNaturalIdTest extends BaseCoreFunctionalTestC
session = openSession(); session = openSession();
for (int i=0; i < 10; i++) { for (int i=0; i < 10; i++) {
session.beginTransaction(); session.beginTransaction();
it = (Another) session.byId(Another.class).load(id); it = session.byId(Another.class).load(id);
if (i == 9) { if (i == 9) {
it.setName("name" + i); it.setName("name" + i);
} }
@ -128,15 +128,16 @@ public abstract class CachedMutableNaturalIdTest extends BaseCoreFunctionalTestC
session = openSession(); session = openSession();
session.beginTransaction(); session.beginTransaction();
it = (Another) session.bySimpleNaturalId(Another.class).load("it"); it = session.bySimpleNaturalId(Another.class).load("it");
assertNull(it); assertNull(it);
assertEquals(0, session.getSessionFactory().getStatistics().getNaturalIdCacheHitCount()); assertEquals( 0, session.getSessionFactory().getStatistics().getNaturalIdCacheHitCount() );
it = (Another) session.byId(Another.class).load(id); it = session.byId(Another.class).load(id);
session.delete(it); session.delete(it);
session.getTransaction().commit(); session.getTransaction().commit();
session.close();
// finally there should be only 2 NaturalIdCache puts : 1. insertion, 2. when updating natural-id from 'it' to 'name9' // 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 @Test
@ -153,7 +154,7 @@ public abstract class CachedMutableNaturalIdTest extends BaseCoreFunctionalTestC
session = openSession(); session = openSession();
session.beginTransaction(); session.beginTransaction();
it = (AllCached) session.byId( AllCached.class ).load( id ); it = session.byId( AllCached.class ).load( id );
it.setName( "it2" ); it.setName( "it2" );
it = (AllCached) session.bySimpleNaturalId( AllCached.class ).load( "it" ); it = (AllCached) session.bySimpleNaturalId( AllCached.class ).load( "it" );
@ -177,19 +178,22 @@ public abstract class CachedMutableNaturalIdTest extends BaseCoreFunctionalTestC
b.assA = a; b.assA = a;
a.assB.add( b ); a.assB.add( b );
session.getTransaction().commit(); session.getTransaction().commit();
session.clear(); session.close();
session = openSession();
session.beginTransaction(); session.beginTransaction();
session.buildLockRequest(LockOptions.NONE).lock(b); // HHH-7513 failure during reattachment session.buildLockRequest(LockOptions.NONE).lock( b ); // HHH-7513 failure during reattachment
session.delete(b.assA); session.delete( b.assA );
session.delete(b); session.delete( b );
session.flush();
session.getTransaction().commit();
session.clear();
// true if the re-attachment worked // true if the re-attachment worked
assertEquals( session.createQuery( "FROM A" ).list().size(), 0 ); assertEquals( session.createQuery( "FROM A" ).list().size(), 0 );
assertEquals( session.createQuery( "FROM B" ).list().size(), 0 ); assertEquals( session.createQuery( "FROM B" ).list().size(), 0 );
session.getTransaction().commit();
session.close();
} }
} }

View File

@ -54,9 +54,11 @@ public class ProxyNarrowingTest extends BaseCoreFunctionalTestCase {
session = openSession(); session = openSession();
try { try {
session.beginTransaction();
// load a proxified version of the entity into the session: the proxy is based on the AbstractEntity class // 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. // 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(); AbstractEntity abstractEntityProxy = reference.getEntity();
assertTrue( ( abstractEntityProxy instanceof HibernateProxy ) && !Hibernate.isInitialized( abstractEntityProxy ) ); assertTrue( ( abstractEntityProxy instanceof HibernateProxy ) && !Hibernate.isInitialized( abstractEntityProxy ) );
@ -64,11 +66,18 @@ public class ProxyNarrowingTest extends BaseCoreFunctionalTestCase {
assertTrue( Hibernate.isInitialized( abstractEntityProxy ) ); assertTrue( Hibernate.isInitialized( abstractEntityProxy ) );
// load the concrete class via session.load to trigger the StatefulPersistenceContext.narrowProxy code // 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 // the new proxy created should be initialized
assertTrue( Hibernate.isInitialized( concreteEntityProxy ) ); assertTrue( Hibernate.isInitialized( concreteEntityProxy ) );
assertTrue( session.contains( concreteEntityProxy ) ); assertTrue( session.contains( concreteEntityProxy ) );
// clean up
session.delete( reference );
session.delete( concreteEntityProxy );
session.getTransaction().commit();
} }
finally { finally {
session.close(); session.close();

View File

@ -38,8 +38,11 @@ public class QuoteTest extends BaseNonConfigCoreFunctionalTestCase {
@Test @Test
public void testQuoteManytoMany() { public void testQuoteManytoMany() {
String role = User.class.getName() + ".roles";
assertEquals( "User_Role", metadata().getCollectionBinding( role ).getCollectionTable().getName() );
Session s = openSession(); Session s = openSession();
Transaction tx = s.beginTransaction(); s.beginTransaction();
User u = new User(); User u = new User();
s.persist( u ); s.persist( u );
Role r = new Role(); Role r = new Role();
@ -47,11 +50,9 @@ public class QuoteTest extends BaseNonConfigCoreFunctionalTestCase {
u.getRoles().add( r ); u.getRoles().add( r );
s.flush(); s.flush();
s.clear(); s.clear();
u = (User) s.get( User.class, u.getId() ); u = s.get( User.class, u.getId() );
assertEquals( 1, u.getRoles().size() ); assertEquals( 1, u.getRoles().size() );
tx.rollback(); s.getTransaction().rollback();
String role = User.class.getName() + ".roles";
assertEquals( "User_Role", metadata().getCollectionBinding( role ).getCollectionTable().getName() );
s.close(); s.close();
} }
@ -66,11 +67,11 @@ public class QuoteTest extends BaseNonConfigCoreFunctionalTestCase {
s.persist( house ); s.persist( house );
s.persist( user ); s.persist( user );
s.getTransaction().commit(); s.getTransaction().commit();
s.clear(); s.close();
s = openSession(); s = openSession();
s.getTransaction().begin(); s.getTransaction().begin();
user = (User) s.get( User.class, user.getId() ); user = s.get( User.class, user.getId() );
assertNotNull( user ); assertNotNull( user );
assertNotNull( user.getHouse() ); assertNotNull( user.getHouse() );
// seems trivial, but if quoting normalization worked on the join column, these should all be the same // 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( container2 );
s.persist( container1 ); s.persist( container1 );
s.getTransaction().commit(); s.getTransaction().commit();
s.clear(); s.close();
Container result = (Container) s.get( Container.class, container1.id ); s = openSession();
s.beginTransaction();
Container result = s.get( Container.class, container1.id );
assertNotNull( result ); assertNotNull( result );
assertNotNull( result.items ); assertNotNull( result.items );
assertEquals( 2, result.items.size() ); 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 @Override
@ -118,7 +135,7 @@ public class QuoteTest extends BaseNonConfigCoreFunctionalTestCase {
}; };
} }
@Entity @Entity( name = "Item" )
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
private static abstract class Item { private static abstract class Item {

View File

@ -9,7 +9,7 @@ package org.hibernate.test.subselect;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import junit.framework.Assert; import org.junit.Assert;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.dialect.H2Dialect; import org.hibernate.dialect.H2Dialect;
@ -37,6 +37,8 @@ public class CompositeIdTypeBindingTest extends BaseCoreFunctionalTestCase {
@Test @Test
public void testCompositeTypeBinding() { public void testCompositeTypeBinding() {
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// prepare test data
Session session = openSession(); Session session = openSession();
session.beginTransaction(); session.beginTransaction();
@ -45,18 +47,18 @@ public class CompositeIdTypeBindingTest extends BaseCoreFunctionalTestCase {
employeegroup.addEmployee( new Employee( "david" ) ); employeegroup.addEmployee( new Employee( "david" ) );
session.save( employeegroup ); session.save( employeegroup );
employeegroup = new EmployeeGroup( new EmployeeGroupId( "c", "d" ) ); employeegroup = new EmployeeGroup( new EmployeeGroupId( "c", "d" ) );
employeegroup.addEmployee( new Employee( "gail" ) ); employeegroup.addEmployee( new Employee( "gail" ) );
employeegroup.addEmployee( new Employee( "steve" ) ); employeegroup.addEmployee( new Employee( "steve" ) );
session.save( employeegroup ); session.save( employeegroup );
session.getTransaction().commit(); session.getTransaction().commit();
session.close(); session.close();
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Perform the test
session = openSession(); session = openSession();
session.beginTransaction();
List<EmployeeGroupId> parameters = new ArrayList<EmployeeGroupId>(); List<EmployeeGroupId> parameters = new ArrayList<EmployeeGroupId>();
parameters.add( new EmployeeGroupId( "a", "b" ) ); parameters.add( new EmployeeGroupId( "a", "b" ) );
@ -73,6 +75,22 @@ public class CompositeIdTypeBindingTest extends BaseCoreFunctionalTestCase {
Assert.assertEquals( "a", employeegroup.getId().getGroupName() ); Assert.assertEquals( "a", employeegroup.getId().getGroupName() );
Assert.assertNotNull( employeegroup.getEmployees() ); Assert.assertNotNull( employeegroup.getEmployees() );
Assert.assertEquals( 2, employeegroup.getEmployees().size() ); Assert.assertEquals( 2, employeegroup.getEmployees().size() );
session.getTransaction().commit();
session.close();
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// clean up test data
session = openSession();
session.beginTransaction();
List<EmployeeGroup> 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(); session.close();
} }
} }

View File

@ -158,4 +158,11 @@ abstract public class DialectChecks {
return dialect.supportsLockTimeouts(); return dialect.supportsLockTimeouts();
} }
} }
public static class DoubleQuoteQuoting implements DialectCheck {
@Override
public boolean isMatch(Dialect dialect) {
return '\"' == dialect.openQuote() && '\"' == dialect.closeQuote();
}
}
} }

View File

@ -33,6 +33,8 @@ Working list of changes for 5.0
* Valid `hibernate.cache.default_cache_concurrency_strategy` setting values are now defined via * 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` `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 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 TODOs
===== =====