From 8d3b2e723b976429d81e188c4cc3b824491b84b7 Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Tue, 8 Sep 2015 14:01:49 +0100 Subject: [PATCH] HHH-9996 - Finish Derby database profile --- databases/derby/matrix.gradle | 2 +- .../derby/resources/hibernate.properties | 1 - .../hibernate/engine/spi/ExtraStateTest.java | 2 + .../SequenceHiLoGeneratorNoIncrementTest.java | 100 +++---- .../id/SequenceHiLoGeneratorTest.java | 84 +++--- .../hibernate/id/SequenceValueExtractor.java | 65 +++++ .../test/annotations/xml/ejb3/CarModel.java | 2 +- .../annotations/xml/ejb3/Ejb3XmlTest.java | 15 +- .../collection/map/PersistentMapTest.java | 3 + .../test/component/basic2/Component.java | 1 + .../test/hql/ASTParserLoadingTest.java | 69 ++++- .../hibernate/test/hql/CastFunctionTest.java | 26 +- .../test/legacy/CompositeIdId.hbm.xml | 4 +- .../hibernate/test/legacy/CompositeIdId.java | 12 +- .../org/hibernate/test/legacy/FooBarTest.java | 27 +- .../test/legacy/SQLFunctionsTest.java | 3 +- .../hibernate/test/legacy/SQLLoaderTest.java | 69 +++-- .../genericApi/BasicGetLoadAccessTest.java | 2 +- .../genericApi/ProxiedGetLoadAccessTest.java | 2 +- .../hibernate/test/optlock/Document.hbm.xml | 4 +- .../schemaupdate/ForeignKeyMigrationTest.java | 4 + .../test/schemaupdate/SchemaExportTest.java | 2 +- .../test/schemaupdate/TestFkUpdating.java | 2 + .../org/hibernate/test/sorted/SortTest.java | 3 + .../custom/CustomStoredProcTestSupport.java | 6 +- .../sql/hand/custom/db2/DB2CustomSQLTest.java | 4 + .../hand/custom/derby/DerbyCustomSQLTest.java | 22 ++ .../custom/derby/DerbyStoreProcedures.java | 52 ++++ .../sql/hand/custom/derby/Mappings.hbm.xml | 275 ++++++++++++++++++ .../subselect/CompositeIdTypeBindingTest.java | 4 +- .../test/temporal/TimePropertyTest.java | 2 + .../test/temporal/TimestampPropertyTest.java | 2 + .../test/tm/BeforeCompletionFailureTest.java | 2 +- .../converter/ElementCollectionTests.java | 2 +- .../test/annotations/xml/ejb3/orm.xml | 1 + .../test/cascade/DetachAndContainsTest.java | 3 + .../hibernate/jpa/test/cdi/BasicCDITest.java | 2 + .../connection/DataSourceInjectionTest.java | 5 + .../hibernate/jpa/test/convert/QueryTest.java | 3 + .../jpa/test/criteria/basic/CastTest.java | 3 + .../test/criteria/enumcollection/User.java | 1 + .../criteria/selectcase/SelectCaseTest.java | 2 + .../jpa/test/graphs/EntityGraphTest.java | 4 + .../manytomany/sametable/BasicSametable.java | 8 +- ...tyAuditStrategyRevEndTestCustomRevEnt.java | 8 +- .../ValidityAuditStrategyRevEndTsTest.java | 8 +- .../org/hibernate/testing/DialectChecks.java | 12 + .../junit4/BaseCoreFunctionalTestCase.java | 30 +- libraries.gradle | 2 +- 49 files changed, 750 insertions(+), 217 deletions(-) create mode 100644 hibernate-core/src/test/java/org/hibernate/id/SequenceValueExtractor.java create mode 100644 hibernate-core/src/test/java/org/hibernate/test/sql/hand/custom/derby/DerbyCustomSQLTest.java create mode 100644 hibernate-core/src/test/java/org/hibernate/test/sql/hand/custom/derby/DerbyStoreProcedures.java create mode 100644 hibernate-core/src/test/java/org/hibernate/test/sql/hand/custom/derby/Mappings.hbm.xml diff --git a/databases/derby/matrix.gradle b/databases/derby/matrix.gradle index d5a657bec0..bedc6e15fa 100644 --- a/databases/derby/matrix.gradle +++ b/databases/derby/matrix.gradle @@ -5,7 +5,7 @@ * See the lgpl.txt file in the root directory or . */ //databaseProfile { - jdbcDependency 'org.apache.derby:derby:10.10.2.0' + jdbcDependency 'org.apache.derby:derby:10.11.1.1' // testing { // beforeSuite { diff --git a/databases/derby/resources/hibernate.properties b/databases/derby/resources/hibernate.properties index de97dbe2e4..88b2ed2062 100644 --- a/databases/derby/resources/hibernate.properties +++ b/databases/derby/resources/hibernate.properties @@ -21,6 +21,5 @@ hibernate.max_fetch_depth 5 hibernate.cache.region_prefix hibernate.test hibernate.cache.region.factory_class org.hibernate.testing.cache.CachingRegionFactory -javax.persistence.validation.mode=NONE hibernate.service.allow_crawling=false hibernate.session.events.log=true \ No newline at end of file diff --git a/hibernate-core/src/test/java/org/hibernate/engine/spi/ExtraStateTest.java b/hibernate-core/src/test/java/org/hibernate/engine/spi/ExtraStateTest.java index ed50ee9033..0410345683 100644 --- a/hibernate-core/src/test/java/org/hibernate/engine/spi/ExtraStateTest.java +++ b/hibernate-core/src/test/java/org/hibernate/engine/spi/ExtraStateTest.java @@ -14,6 +14,7 @@ import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; +import javax.persistence.Table; import org.hibernate.Session; import org.hibernate.internal.SessionImpl; @@ -68,6 +69,7 @@ public class ExtraStateTest extends BaseCoreFunctionalTestCase { } @Entity + @Table(name = "ChineseTakeawayRestaurant") public class ChineseTakeawayRestaurant { private long id; diff --git a/hibernate-core/src/test/java/org/hibernate/id/SequenceHiLoGeneratorNoIncrementTest.java b/hibernate-core/src/test/java/org/hibernate/id/SequenceHiLoGeneratorNoIncrementTest.java index 878cf88bd1..00aab051e2 100644 --- a/hibernate-core/src/test/java/org/hibernate/id/SequenceHiLoGeneratorNoIncrementTest.java +++ b/hibernate-core/src/test/java/org/hibernate/id/SequenceHiLoGeneratorNoIncrementTest.java @@ -6,42 +6,32 @@ */ package org.hibernate.id; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.Collections; import java.util.Properties; import org.hibernate.Session; +import org.hibernate.Transaction; import org.hibernate.boot.Metadata; import org.hibernate.boot.MetadataSources; -import org.hibernate.boot.model.naming.Identifier; import org.hibernate.boot.model.naming.ObjectNameNormalizer; -import org.hibernate.boot.model.relational.SimpleAuxiliaryDatabaseObject; import org.hibernate.boot.registry.StandardServiceRegistry; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.boot.spi.MetadataBuildingContext; import org.hibernate.cfg.AvailableSettings; -import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; -import org.hibernate.engine.jdbc.spi.JdbcServices; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.id.enhanced.SequenceStyleGenerator; import org.hibernate.internal.SessionImpl; -import org.hibernate.jdbc.Work; import org.hibernate.type.StandardBasicTypes; -import org.hibernate.testing.DialectChecks; -import org.hibernate.testing.RequiresDialectFeature; -import org.hibernate.testing.env.TestingDatabaseInfo; -import org.hibernate.testing.junit4.BaseUnitTestCase; -import org.hibernate.testing.boot.BasicTestingJdbcServiceImpl; -import org.hibernate.testing.boot.MetadataBuildingContextTestingImpl; import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.hibernate.testing.DialectChecks; +import org.hibernate.testing.RequiresDialectFeature; +import org.hibernate.testing.boot.MetadataBuildingContextTestingImpl; +import org.hibernate.testing.junit4.BaseUnitTestCase; + import static org.junit.Assert.assertEquals; /** @@ -50,25 +40,21 @@ import static org.junit.Assert.assertEquals; * * @author Steve Ebersole */ -@SuppressWarnings({ "deprecation" }) -@RequiresDialectFeature( DialectChecks.SupportsSequences.class ) +@SuppressWarnings({"deprecation"}) +@RequiresDialectFeature(DialectChecks.SupportsSequences.class) public class SequenceHiLoGeneratorNoIncrementTest extends BaseUnitTestCase { private static final String TEST_SEQUENCE = "test_sequence"; private StandardServiceRegistry serviceRegistry; private SessionFactoryImplementor sessionFactory; private SequenceStyleGenerator generator; - private SessionImplementor session; + private SessionImplementor sessionImpl; + private SequenceValueExtractor sequenceValueExtractor; @Before public void setUp() throws Exception { - BasicTestingJdbcServiceImpl jdbcServices = new BasicTestingJdbcServiceImpl(); - jdbcServices.prepare( false ); - serviceRegistry = new StandardServiceRegistryBuilder() .enableAutoClose() - .addService( JdbcEnvironment.class, jdbcServices.getJdbcEnvironment() ) - .addService( JdbcServices.class, jdbcServices ) .applySetting( AvailableSettings.HBM2DDL_AUTO, "create-drop" ) .build(); @@ -94,13 +80,14 @@ public class SequenceHiLoGeneratorNoIncrementTest extends BaseUnitTestCase { generator.registerExportables( metadata.getDatabase() ); sessionFactory = (SessionFactoryImplementor) metadata.buildSessionFactory(); + sequenceValueExtractor = new SequenceValueExtractor( sessionFactory.getDialect(), TEST_SEQUENCE ); } @After public void tearDown() throws Exception { - if(session != null && !session.isClosed()) { - ((Session)session).close(); - } + if ( sessionImpl != null && !sessionImpl.isClosed() ) { + ((Session) sessionImpl).close(); + } if ( sessionFactory != null ) { sessionFactory.close(); } @@ -111,58 +98,49 @@ public class SequenceHiLoGeneratorNoIncrementTest extends BaseUnitTestCase { @Test public void testHiLoAlgorithm() { - session = (SessionImpl) sessionFactory.openSession(); - ((Session)session).beginTransaction(); + sessionImpl = (SessionImpl) sessionFactory.openSession(); // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // initially sequence should be uninitialized - assertEquals( 0L, extractSequenceValue( (session) ) ); + assertEquals( 0L, extractSequenceValue( (sessionImpl) ) ); + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // historically the hilo generators skipped the initial block of values; // so the first generated id value is maxlo + 1, here be 4 - Long generatedValue = (Long) generator.generate( session, null ); - assertEquals( 1L, generatedValue.longValue() ); + assertEquals( 1L, generateValue() ); + // which should also perform the first read on the sequence which should set it to its "start with" value (1) - assertEquals( 1L, extractSequenceValue( (session) ) ); + assertEquals( 1L, extractSequenceValue( (sessionImpl) ) ); // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - generatedValue = (Long) generator.generate( session, null ); - assertEquals( 2L, generatedValue.longValue() ); - assertEquals( 2L, extractSequenceValue( (session) ) ); + assertEquals( 2L, generateValue() ); + assertEquals( 2L, extractSequenceValue( (sessionImpl) ) ); // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - generatedValue = (Long) generator.generate( session, null ); - assertEquals( 3L, generatedValue.longValue() ); - assertEquals( 3L, extractSequenceValue( (session) ) ); + assertEquals( 3L, generateValue() ); + assertEquals( 3L, extractSequenceValue( (sessionImpl) ) ); // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - generatedValue = (Long) generator.generate( session, null ); - assertEquals( 4L, generatedValue.longValue() ); - assertEquals( 4L, extractSequenceValue( (session) ) ); + assertEquals( 4L, generateValue() ); + assertEquals( 4L, extractSequenceValue( (sessionImpl) ) ); // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - generatedValue = (Long) generator.generate( session, null ); - assertEquals( 5L, generatedValue.longValue() ); - assertEquals( 5L, extractSequenceValue( (session) ) ); + assertEquals( 5L, generateValue() ); + assertEquals( 5L, extractSequenceValue( (sessionImpl) ) ); - ((Session)session).getTransaction().commit(); - ((Session)session).close(); + ((Session) sessionImpl).close(); } - private long extractSequenceValue(final SessionImplementor session) { - class WorkImpl implements Work { - private long value; - public void execute(Connection connection) throws SQLException { - - PreparedStatement query = session.getJdbcCoordinator().getStatementPreparer().prepareStatement( "select currval('" + TEST_SEQUENCE + "');" ); - ResultSet resultSet = session.getJdbcCoordinator().getResultSetReturn().extract( query ); - resultSet.next(); - value = resultSet.getLong( 1 ); - } - } - WorkImpl work = new WorkImpl(); - ( (Session) session ).doWork( work ); - return work.value; + private long extractSequenceValue(SessionImplementor sessionImpl) { + return sequenceValueExtractor.extractSequenceValue( sessionImpl ); + } + + private long generateValue() { + Long generatedValue; + Transaction transaction = ((Session) sessionImpl).beginTransaction(); + generatedValue = (Long) generator.generate( sessionImpl, null ); + transaction.commit(); + return generatedValue.longValue(); } } diff --git a/hibernate-core/src/test/java/org/hibernate/id/SequenceHiLoGeneratorTest.java b/hibernate-core/src/test/java/org/hibernate/id/SequenceHiLoGeneratorTest.java index dc85953a81..bc5433a913 100644 --- a/hibernate-core/src/test/java/org/hibernate/id/SequenceHiLoGeneratorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/id/SequenceHiLoGeneratorTest.java @@ -6,13 +6,10 @@ */ package org.hibernate.id; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; import java.util.Properties; import org.hibernate.Session; +import org.hibernate.Transaction; import org.hibernate.boot.Metadata; import org.hibernate.boot.MetadataSources; import org.hibernate.boot.registry.StandardServiceRegistry; @@ -22,33 +19,35 @@ import org.hibernate.cfg.AvailableSettings; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.internal.SessionImpl; -import org.hibernate.jdbc.Work; import org.hibernate.type.StandardBasicTypes; -import org.hibernate.testing.DialectChecks; -import org.hibernate.testing.RequiresDialectFeature; -import org.hibernate.testing.junit4.BaseUnitTestCase; -import org.hibernate.testing.boot.MetadataBuildingContextTestingImpl; import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.hibernate.testing.DialectChecks; +import org.hibernate.testing.RequiresDialectFeature; +import org.hibernate.testing.boot.MetadataBuildingContextTestingImpl; +import org.hibernate.testing.junit4.BaseUnitTestCase; + import static org.junit.Assert.assertEquals; /** * I went back to 3.3 source and grabbed the code/logic as it existed back then and crafted this * unit test so that we can make sure the value keep being generated in the expected manner - * + * * @author Steve Ebersole */ -@SuppressWarnings({ "deprecation" }) -@RequiresDialectFeature( DialectChecks.SupportsSequences.class ) +@SuppressWarnings({"deprecation"}) +@RequiresDialectFeature(DialectChecks.SupportsSequences.class) public class SequenceHiLoGeneratorTest extends BaseUnitTestCase { private static final String TEST_SEQUENCE = "test_sequence"; private StandardServiceRegistry serviceRegistry; private SessionFactoryImplementor sessionFactory; private SequenceHiLoGenerator generator; + private SessionImplementor sessionImpl; + private SequenceValueExtractor sequenceValueExtractor; @Before public void setUp() throws Exception { @@ -62,7 +61,10 @@ public class SequenceHiLoGeneratorTest extends BaseUnitTestCase { Properties properties = new Properties(); properties.setProperty( SequenceGenerator.SEQUENCE, TEST_SEQUENCE ); properties.setProperty( SequenceHiLoGenerator.MAX_LO, "3" ); - properties.put( PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER, buildingContext.getObjectNameNormalizer() ); + properties.put( + PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER, + buildingContext.getObjectNameNormalizer() + ); generator = new SequenceHiLoGenerator(); generator.configure( StandardBasicTypes.LONG, properties, serviceRegistry ); @@ -71,6 +73,7 @@ public class SequenceHiLoGeneratorTest extends BaseUnitTestCase { generator.registerExportables( metadata.getDatabase() ); sessionFactory = (SessionFactoryImplementor) metadata.buildSessionFactory(); + sequenceValueExtractor = new SequenceValueExtractor( sessionFactory.getDialect(), TEST_SEQUENCE ); } @After @@ -85,61 +88,50 @@ public class SequenceHiLoGeneratorTest extends BaseUnitTestCase { @Test public void testHiLoAlgorithm() { - SessionImpl session = (SessionImpl) sessionFactory.openSession(); - session.beginTransaction(); + sessionImpl = (SessionImpl) sessionFactory.openSession(); // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // initially sequence should be uninitialized - assertEquals( 0L, extractSequenceValue( session ) ); + assertEquals( 0L, extractSequenceValue( sessionImpl ) ); // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // historically the hilo generators skipped the initial block of values; // so the first generated id value is maxlo + 1, here be 4 - Long generatedValue = (Long) generator.generate( session, null ); - assertEquals( 4L, generatedValue.longValue() ); + assertEquals( 4L, generateValue() ); // which should also perform the first read on the sequence which should set it to its "start with" value (1) - assertEquals( 1L, extractSequenceValue( session ) ); + assertEquals( 1L, extractSequenceValue( sessionImpl ) ); // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - generatedValue = (Long) generator.generate( session, null ); - assertEquals( 5L, generatedValue.longValue() ); - assertEquals( 1L, extractSequenceValue( session ) ); + assertEquals( 5L, generateValue() ); + assertEquals( 1L, extractSequenceValue( sessionImpl ) ); // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - generatedValue = (Long) generator.generate( session, null ); - assertEquals( 6L, generatedValue.longValue() ); - assertEquals( 1L, extractSequenceValue( session ) ); + assertEquals( 6L, generateValue() ); + assertEquals( 1L, extractSequenceValue( sessionImpl ) ); // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - generatedValue = (Long) generator.generate( session, null ); - assertEquals( 7L, generatedValue.longValue() ); + assertEquals( 7L, generateValue() ); // unlike the newer strategies, the db value will not get update here. It gets updated on the next invocation // after a clock over - assertEquals( 1L, extractSequenceValue( session ) ); + assertEquals( 1L, extractSequenceValue( sessionImpl ) ); // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - generatedValue = (Long) generator.generate( session, null ); - assertEquals( 8L, generatedValue.longValue() ); + assertEquals( 8L, generateValue() ); // this should force an increment in the sequence value - assertEquals( 2L, extractSequenceValue( session ) ); + assertEquals( 2L, extractSequenceValue( sessionImpl ) ); - session.getTransaction().commit(); - session.close(); + ((Session) sessionImpl).close(); } - private long extractSequenceValue(final SessionImplementor session) { - class WorkImpl implements Work { - private long value; + private long extractSequenceValue(SessionImplementor sessionImpl) { + return sequenceValueExtractor.extractSequenceValue( sessionImpl ); + } - public void execute(Connection connection) throws SQLException { - PreparedStatement query = session.getJdbcCoordinator().getStatementPreparer().prepareStatement( "select currval('" + TEST_SEQUENCE + "');" ); - ResultSet resultSet = session.getJdbcCoordinator().getResultSetReturn().extract( query ); - resultSet.next(); - value = resultSet.getLong( 1 ); - } - } - WorkImpl work = new WorkImpl(); - ( (Session) session ).doWork( work ); - return work.value; + private long generateValue() { + Long generatedValue; + Transaction transaction = ((Session) sessionImpl).beginTransaction(); + generatedValue = (Long) generator.generate( sessionImpl, null ); + transaction.commit(); + return generatedValue.longValue(); } } diff --git a/hibernate-core/src/test/java/org/hibernate/id/SequenceValueExtractor.java b/hibernate-core/src/test/java/org/hibernate/id/SequenceValueExtractor.java new file mode 100644 index 0000000000..61438290e1 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/id/SequenceValueExtractor.java @@ -0,0 +1,65 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.id; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; + +import org.hibernate.Session; +import org.hibernate.Transaction; +import org.hibernate.dialect.DerbyDialect; +import org.hibernate.dialect.Dialect; +import org.hibernate.engine.spi.SessionImplementor; +import org.hibernate.jdbc.Work; + +/** + * @author Andrea Boriero + */ +public class SequenceValueExtractor { + + private final Dialect dialect; + private final String queryString; + + public SequenceValueExtractor(Dialect dialect, String sequenceName) { + this.dialect = dialect; + if ( dialect instanceof DerbyDialect ) { + queryString = "VALUES SYSCS_UTIL.SYSCS_PEEK_AT_SEQUENCE('HIBERNATE_ORM_TEST', '" + sequenceName.toUpperCase() + "')"; + } + else { + queryString = "select currval('" + sequenceName + "');"; + } + } + + public long extractSequenceValue(final SessionImplementor sessionImpl) { + class WorkImpl implements Work { + private long value; + + public void execute(Connection connection) throws SQLException { + Session session = (Session) sessionImpl; + Transaction transaction = session.beginTransaction(); + final PreparedStatement query = sessionImpl.getJdbcCoordinator() + .getStatementPreparer() + .prepareStatement( queryString ); + ResultSet resultSet = sessionImpl.getJdbcCoordinator().getResultSetReturn().extract( query ); + resultSet.next(); + value = resultSet.getLong( 1 ); + + resultSet.close(); + transaction.commit(); + + if ( dialect instanceof DerbyDialect ) { + value--; + } + } + } + WorkImpl work = new WorkImpl(); + ((Session) sessionImpl).doWork( work ); + return work.value; + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/xml/ejb3/CarModel.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/xml/ejb3/CarModel.java index 14a46df8dc..2c6fbe7770 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/xml/ejb3/CarModel.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/xml/ejb3/CarModel.java @@ -12,7 +12,7 @@ import java.util.Date; * @author Emmanuel Bernard */ public class CarModel extends Model { - @Column(name="`year`") + @Column(name="model_year") private Date year; public Date getYear() { diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/xml/ejb3/Ejb3XmlTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/xml/ejb3/Ejb3XmlTest.java index e117a2b8b0..7726f23fc1 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/xml/ejb3/Ejb3XmlTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/xml/ejb3/Ejb3XmlTest.java @@ -14,6 +14,7 @@ import org.junit.Test; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; +import org.hibernate.dialect.DerbyDialect; import org.hibernate.dialect.PostgreSQL81Dialect; import org.hibernate.dialect.PostgreSQLDialect; import org.hibernate.dialect.TeradataDialect; @@ -30,13 +31,13 @@ import static org.junit.Assert.assertNotNull; */ public class Ejb3XmlTest extends BaseCoreFunctionalTestCase { @Test - @SkipForDialects ( { - @SkipForDialect(value = { PostgreSQL81Dialect.class, PostgreSQLDialect.class }, - comment = "postgresql jdbc driver does not implement the setQueryTimeout method"), - @SkipForDialect(value = TeradataDialect.class , - jiraKey = "HHH-8190", - comment = "uses Teradata reserved word - year") -} ) + @SkipForDialects({ + @SkipForDialect(value = {PostgreSQL81Dialect.class, PostgreSQLDialect.class}, + comment = "postgresql jdbc driver does not implement the setQueryTimeout method"), + @SkipForDialect(value = TeradataDialect.class, + jiraKey = "HHH-8190", + comment = "uses Teradata reserved word - year") + }) public void testEjb3Xml() throws Exception { Session s = openSession(); Transaction tx = s.beginTransaction(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/collection/map/PersistentMapTest.java b/hibernate-core/src/test/java/org/hibernate/test/collection/map/PersistentMapTest.java index 86f864cdfd..526559a3e5 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/collection/map/PersistentMapTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/collection/map/PersistentMapTest.java @@ -24,6 +24,7 @@ import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.MapKeyColumn; import javax.persistence.OneToMany; +import javax.persistence.Table; import org.hibernate.Query; import org.hibernate.Session; @@ -197,6 +198,7 @@ public class PersistentMapTest extends BaseCoreFunctionalTestCase { } @Entity + @Table(name = "MyUser") private static class User implements Serializable { @Id @GeneratedValue private Integer id; @@ -207,6 +209,7 @@ public class PersistentMapTest extends BaseCoreFunctionalTestCase { } @Entity + @Table(name = "UserData") private static class UserData { @Id @GeneratedValue private Integer id; diff --git a/hibernate-core/src/test/java/org/hibernate/test/component/basic2/Component.java b/hibernate-core/src/test/java/org/hibernate/test/component/basic2/Component.java index e2b27cc0b8..ef6cf98f9c 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/component/basic2/Component.java +++ b/hibernate-core/src/test/java/org/hibernate/test/component/basic2/Component.java @@ -33,6 +33,7 @@ public class Component { Set stuffs = new HashSet(); @Entity + @Table(name = "stuff") public static class Stuff { @Id private Long id; diff --git a/hibernate-core/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java b/hibernate-core/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java index ab9f335404..abb35ba1eb 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java @@ -19,6 +19,7 @@ import org.hibernate.cfg.Environment; import org.hibernate.dialect.AbstractHANADialect; import org.hibernate.dialect.CUBRIDDialect; import org.hibernate.dialect.DB2Dialect; +import org.hibernate.dialect.DerbyDialect; import org.hibernate.dialect.H2Dialect; import org.hibernate.dialect.HSQLDialect; import org.hibernate.dialect.IngresDialect; @@ -754,7 +755,12 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase { "from Human where cast(? as string) is null" : "from Human where ? is null" ; - s.createQuery( query ).setParameter( 0, null ).list(); + if ( getDialect() instanceof DerbyDialect ) { + s.createQuery( query ).setParameter( 0, "null" ).list(); + } + else { + s.createQuery( query ).setParameter( 0, null ).list(); + } s.getTransaction().commit(); s.close(); @@ -1386,10 +1392,12 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase { public void testSimpleSelectWithLimitAndOffset() throws Exception { // just checking correctness of param binding code... Session session = openSession(); + Transaction t = session.beginTransaction(); session.createQuery( "from Animal" ) .setFirstResult( 2 ) .setMaxResults( 1 ) .list(); + t.commit(); session.close(); } @@ -1567,6 +1575,7 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase { // which in-and-of-itself is not necessarily bad. But somewhere later // the choices made there caused joins to be dropped. Session s = openSession(); + Transaction t = s.beginTransaction(); String qryString = "select a.id, a.description" + " from Animal a" + @@ -1599,6 +1608,7 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase { " where h = f1" + ")"; s.createQuery( qryString ).list(); + t.commit(); s.close(); } @@ -2604,8 +2614,8 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase { an.setBodyWeight(123.45f); session.persist( an ); String str = (String) session.createQuery("select str(an.bodyWeight) from Animal an where str(an.bodyWeight) like '%1%'").uniqueResult(); - if ( getDialect() instanceof DB2Dialect || getDialect() instanceof TeradataDialect) { - assertTrue( str.startsWith("1.234") ); + if ( (getDialect() instanceof DB2Dialect || getDialect() instanceof TeradataDialect) && !(getDialect() instanceof DerbyDialect) ) { + assertTrue( str.startsWith( "1.234" ) ); } else //noinspection deprecation if ( getDialect() instanceof SybaseDialect || getDialect() instanceof Sybase11Dialect || getDialect() instanceof SybaseASE15Dialect || getDialect() instanceof SybaseAnywhereDialect || getDialect() instanceof SQLServerDialect ) { @@ -2894,9 +2904,11 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase { public void testFromOnly() throws Exception { createTestBaseData(); Session session = openSession(); + Transaction t = session.beginTransaction(); List results = session.createQuery( "from Animal" ).list(); assertEquals( "Incorrect result size", 2, results.size() ); assertTrue( "Incorrect result return type", results.get( 0 ) instanceof Animal ); + t.commit(); session.close(); destroyTestBaseData(); } @@ -2905,9 +2917,11 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase { public void testSimpleSelect() throws Exception { createTestBaseData(); Session session = openSession(); + Transaction t = session.beginTransaction(); List results = session.createQuery( "select a from Animal as a" ).list(); assertEquals( "Incorrect result size", 2, results.size() ); assertTrue( "Incorrect result return type", results.get( 0 ) instanceof Animal ); + t.commit(); session.close(); destroyTestBaseData(); } @@ -2916,8 +2930,10 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase { public void testEntityPropertySelect() throws Exception { createTestBaseData(); Session session = openSession(); + Transaction t = session.beginTransaction(); List results = session.createQuery( "select a.mother from Animal as a" ).list(); assertTrue( "Incorrect result return type", results.get( 0 ) instanceof Animal ); + t.commit(); session.close(); destroyTestBaseData(); } @@ -2927,6 +2943,7 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase { createTestBaseData(); Session session = openSession(); + Transaction t = session.beginTransaction(); List results = session.createQuery( "from Animal an where an.bodyWeight > 10" ).list(); assertEquals( "Incorrect result size", 1, results.size() ); @@ -2945,6 +2962,7 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase { results = session.createQuery( "from Animal an where (an.bodyWeight > 10 and an.bodyWeight < 100) or an.bodyWeight is null" ).list(); assertEquals( "Incorrect result size", 1, results.size() ); + t.commit(); session.close(); destroyTestBaseData(); @@ -2955,6 +2973,7 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase { createTestBaseData(); Session session = openSession(); + Transaction t = session.beginTransaction(); List results = session.createQuery( "from Animal an join fetch an.mother" ).list(); assertEquals( "Incorrect result size", 1, results.size() ); @@ -2968,6 +2987,7 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase { mother = ( ( Animal ) results.get( 0 ) ).getMother(); assertTrue( "fetch uninitialized", mother != null && Hibernate.isInitialized( mother ) ); + t.commit(); session.close(); destroyTestBaseData(); @@ -2978,6 +2998,7 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase { createTestBaseData(); Session session = openSession(); + Transaction t = session.beginTransaction(); List results = session.createQuery( "from Animal an join fetch an.offspring" ).list(); assertEquals( "Incorrect result size", 1, results.size() ); assertTrue( "Incorrect result return type", results.get( 0 ) instanceof Animal ); @@ -2990,6 +3011,7 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase { os = ( ( Animal ) results.get( 0 ) ).getOffspring(); assertTrue( "fetch uninitialized", os != null && Hibernate.isInitialized( os ) && os.size() == 1 ); + t.commit(); session.close(); destroyTestBaseData(); @@ -3010,6 +3032,7 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase { session.save( mammal ); session.save( zoo ); txn.commit(); + session.close(); session = openSession(); txn = session.beginTransaction(); @@ -3042,6 +3065,7 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase { session.save( mammal ); session.save( zoo ); txn.commit(); + session.close(); session = openSession(); txn = session.beginTransaction(); @@ -3074,6 +3098,7 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase { session.save( mammal ); session.save( zoo ); txn.commit(); + session.close(); session = openSession(); txn = session.beginTransaction(); @@ -3095,11 +3120,15 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase { public void testProjectionQueries() throws Exception { createTestBaseData(); Session session = openSession(); + Transaction t = session.beginTransaction(); + List results = session.createQuery( "select an.mother.id, max(an.bodyWeight) from Animal an group by an.mother.id" ).list(); // mysql returns nulls in this group by assertEquals( "Incorrect result size", 2, results.size() ); assertTrue( "Incorrect return type", results.get( 0 ) instanceof Object[] ); - assertEquals( "Incorrect return dimensions", 2, ( ( Object[] ) results.get( 0 ) ).length ); + assertEquals( "Incorrect return dimensions", 2, ((Object[]) results.get( 0 )).length ); + + t.commit(); session.close(); destroyTestBaseData(); } @@ -3132,6 +3161,7 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase { createTestBaseData(); Session session = openSession(); + Transaction t = session.beginTransaction(); List results = session.createQuery( "select new Animal(an.description, an.bodyWeight) from Animal an" ).list(); assertEquals( "Incorrect result size", 2, results.size() ); @@ -3210,6 +3240,7 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase { assertEquals( "incorrect result size", 2, results.size() ); assertClassAssignability( Animal.class, results.get( 0 ).getClass() ); + t.commit(); session.close(); destroyTestBaseData(); @@ -3431,7 +3462,7 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase { @Test public void testIllegalMixedTransformerQueries() { Session session = openSession(); - + Transaction t = session.beginTransaction(); try { getSelectNewQuery( session ).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP).list(); fail("'select new' together with a resulttransformer should result in error!"); @@ -3452,7 +3483,7 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase { } catch(HibernateException he) { assertTrue(he.getMessage().indexOf("ResultTransformer")==0); } - + t.commit(); session.close(); } @@ -3467,28 +3498,33 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase { String query = "select an.description as description, an.bodyWeight as bodyWeight from Animal an order by bodyWeight desc"; Session session = openSession(); + Transaction t = session.beginTransaction(); List results = session.createQuery( query ) .setResultTransformer(Transformers.aliasToBean(Animal.class)).list(); + assertEquals( "Incorrect result size", results.size(), 2 ); assertTrue( "Incorrect return type", results.get(0) instanceof Animal ); Animal firstAnimal = (Animal) results.get(0); Animal secondAnimal = (Animal) results.get(1); assertEquals("Mammal #1", firstAnimal.getDescription()); - assertEquals("Mammal #2", secondAnimal.getDescription()); - assertFalse(session.contains(firstAnimal)); + assertEquals( "Mammal #2", secondAnimal.getDescription() ); + assertFalse( session.contains( firstAnimal ) ); + t.commit(); session.close(); session = openSession(); - + t = session.beginTransaction(); Iterator iter = session.createQuery( query ) .setResultTransformer(Transformers.aliasToBean(Animal.class)).iterate(); assertTrue( "Incorrect result size", iter.hasNext() ); assertTrue( "Incorrect return type", iter.next() instanceof Animal ); + t.commit(); session.close(); session = openSession(); + t = session.beginTransaction(); ScrollableResults sr = session.createQuery( query ) .setResultTransformer(Transformers.aliasToBean(Animal.class)).scroll(); @@ -3498,20 +3534,23 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase { assertFalse( session.contains( sr.get( 0 ) ) ); sr.close(); + t.commit(); session.close(); session = openSession(); + t = session.beginTransaction(); results = session.createQuery( "select a from Animal a, Animal b order by a.id" ) .setResultTransformer( DistinctRootEntityResultTransformer.INSTANCE ) .list(); assertEquals( "Incorrect result size", 2, results.size()); - assertTrue( "Incorrect return type", results.get(0) instanceof Animal ); + assertTrue( "Incorrect return type", results.get( 0 ) instanceof Animal ); firstAnimal = (Animal) results.get(0); secondAnimal = (Animal) results.get(1); assertEquals( "Mammal #1", firstAnimal.getDescription() ); assertEquals( "Mammal #2", secondAnimal.getDescription() ); + t.commit(); session.close(); destroyTestBaseData(); @@ -3524,6 +3563,7 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase { String query = "select an as an from Animal an order by bodyWeight desc"; Session session = openSession(); + Transaction t = session.beginTransaction(); List results = session.createQuery( query ) .setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP).list(); @@ -3536,11 +3576,13 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase { Animal secondAnimal = (Animal) map.get("an"); assertEquals( "Mammal #1", firstAnimal.getDescription() ); assertEquals("Mammal #2", secondAnimal.getDescription()); - assertTrue(session.contains(firstAnimal)); + assertTrue( session.contains( firstAnimal)); assertSame( firstAnimal, session.get( Animal.class, firstAnimal.getId() ) ); + t.commit(); session.close(); session = openSession(); + t = session.beginTransaction(); Iterator iter = session.createQuery( query ) .setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP).iterate(); @@ -3550,9 +3592,11 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase { assertEquals( "Mammal #1", firstAnimal.getDescription() ); assertTrue( "Incorrect result size", iter.hasNext() ); + t.commit(); session.close(); session = openSession(); + t = session.beginTransaction(); ScrollableResults sr = session.createQuery( query ) .setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP).scroll(); @@ -3562,6 +3606,7 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase { assertFalse( session.contains( sr.get( 0 ) ) ); sr.close(); + t.commit(); session.close(); destroyTestBaseData(); @@ -3570,6 +3615,7 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase { @Test public void testEJBQLFunctions() throws Exception { Session session = openSession(); + Transaction t = session.beginTransaction(); String hql = "from Animal a where a.description = concat('1', concat('2','3'), '4'||'5')||'0'"; session.createQuery(hql).list(); @@ -3672,6 +3718,7 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase { hql = "from Animal a where a.description like 'x%ax%' escape 'x'"; session.createQuery(hql).list(); + t.commit(); session.close(); } diff --git a/hibernate-core/src/test/java/org/hibernate/test/hql/CastFunctionTest.java b/hibernate-core/src/test/java/org/hibernate/test/hql/CastFunctionTest.java index c482f26198..8262d26e8a 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/hql/CastFunctionTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/hql/CastFunctionTest.java @@ -10,6 +10,7 @@ import javax.persistence.Entity; import javax.persistence.Id; import org.hibernate.Session; +import org.hibernate.dialect.DerbyDialect; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.junit.Test; @@ -36,12 +37,25 @@ public class CastFunctionTest extends BaseCoreFunctionalTestCase { Session s = openSession(); s.beginTransaction(); - // using the short name - s.createQuery( "select cast(e.theLostNumber as string) from MyEntity e" ).list(); - // using the java class name - s.createQuery( "select cast(e.theLostNumber as java.lang.String) from MyEntity e" ).list(); - // using the fqn Hibernate Type name - s.createQuery( "select cast(e.theLostNumber as org.hibernate.type.StringType) from MyEntity e" ).list(); + if ( getDialect() instanceof DerbyDialect ) { + // the conversion from DOUBLE to VARCHAR is not supported by Derby, + // using the short name + s.createQuery( "select cast(char(e.theLostNumber) as string) from MyEntity e" ).list(); + // using the java class name + s.createQuery( "select cast(char(e.theLostNumber) as java.lang.String) from MyEntity e" ).list(); + // using the fqn Hibernate Type name + s.createQuery( "select cast(char(e.theLostNumber) as org.hibernate.type.StringType) from MyEntity e" ) + .list(); + } + else { + // using the short name + s.createQuery( "select cast(e.theLostNumber as string) from MyEntity e" ).list(); + // using the java class name + s.createQuery( "select cast(e.theLostNumber as java.lang.String) from MyEntity e" ).list(); + // using the fqn Hibernate Type name + s.createQuery( "select cast(e.theLostNumber as org.hibernate.type.StringType) from MyEntity e" ) + .list(); + } s.getTransaction().commit(); s.close(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/legacy/CompositeIdId.hbm.xml b/hibernate-core/src/test/java/org/hibernate/test/legacy/CompositeIdId.hbm.xml index 00574420c6..0423b27fcc 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/legacy/CompositeIdId.hbm.xml +++ b/hibernate-core/src/test/java/org/hibernate/test/legacy/CompositeIdId.hbm.xml @@ -9,7 +9,7 @@ - + @@ -23,7 +23,7 @@ - select "system" as {c.system}, id as {c.id}, name as {c.name}, foo as {c.composite.foo}, bar as {c.composite.bar} from CompositeIdId where "system"=? and id=? + select "user" as {c.user}, id as {c.id}, name as {c.name}, foo as {c.composite.foo}, bar as {c.composite.bar} from CompositeIdId where "user"=? and id=? \ No newline at end of file diff --git a/hibernate-core/src/test/java/org/hibernate/test/legacy/CompositeIdId.java b/hibernate-core/src/test/java/org/hibernate/test/legacy/CompositeIdId.java index 10b6a580cf..3f1cb79341 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/legacy/CompositeIdId.java +++ b/hibernate-core/src/test/java/org/hibernate/test/legacy/CompositeIdId.java @@ -18,7 +18,7 @@ import java.io.Serializable; */ public class CompositeIdId implements Serializable { - String system; + String user; String id; String name; CompositeElement composite; @@ -30,11 +30,11 @@ public class CompositeIdId implements Serializable { public void setId(String id) { this.id = id; } - public String getSystem() { - return system; + public String getUser() { + return user; } - public void setSystem(String system) { - this.system = system; + public void setUser(String user) { + this.user = user; } public String getName() { return name; @@ -50,7 +50,7 @@ public class CompositeIdId implements Serializable { // not totally NP or type safe equals, but enough for the unittests. CompositeIdId o = (CompositeIdId) obj; if(o==null) return false; - return o.getSystem().equals(getSystem()) && o.getId().equals(getId()); + return o.getUser().equals( getUser()) && o.getId().equals(getId()); } public CompositeElement getComposite() { return composite; diff --git a/hibernate-core/src/test/java/org/hibernate/test/legacy/FooBarTest.java b/hibernate-core/src/test/java/org/hibernate/test/legacy/FooBarTest.java index cc29b708d1..2f9ac6a319 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/legacy/FooBarTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/legacy/FooBarTest.java @@ -3534,22 +3534,29 @@ public class FooBarTest extends LegacyTestCase { Session s = openSession(); Transaction txn = s.beginTransaction(); Foo foo = new Foo(); - s.save(foo); + s.save( foo ); Foo foo1 = new Foo(); s.save(foo1); - foo.setFoo(foo1); + foo.setFoo( foo1 ); List l = s.createQuery( "select parent, child from Foo parent, Foo child where parent.foo = child" ).list(); assertTrue( "multi-column find", l.size()==1 ); - Iterator rs = s.createQuery( - "select count(distinct child.id), count(distinct parent.id) from Foo parent, Foo child where parent.foo = child" - ).iterate(); - Object[] row = (Object[]) rs.next(); - assertTrue( "multi-column count", ( (Long) row[0] ).intValue()==1 ); - assertTrue( "multi-column count", ( (Long) row[1] ).intValue()==1 ); - assertTrue( !rs.hasNext() ); + Iterator rs = null; + Object[] row = null; + //Derby does not support multiple DISTINCT aggregates + if ( !(getDialect() instanceof DerbyDialect) ) { + rs = s.createQuery( + "select count(distinct child.id), count(distinct parent.id) from Foo parent, Foo child where parent.foo = child" + ).iterate(); - rs = s.createQuery( "select child.id, parent.id, child.long from Foo parent, Foo child where parent.foo = child" ) + row = (Object[]) rs.next(); + assertTrue( "multi-column count", ((Long) row[0]).intValue() == 1 ); + assertTrue( "multi-column count", ((Long) row[1]).intValue() == 1 ); + assertTrue( !rs.hasNext() ); + } + rs = s.createQuery( + "select child.id, parent.id, child.long from Foo parent, Foo child where parent.foo = child" + ) .iterate(); row = (Object[]) rs.next(); assertTrue( "multi-column id", row[0].equals( foo.getFoo().getKey() ) ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/legacy/SQLFunctionsTest.java b/hibernate-core/src/test/java/org/hibernate/test/legacy/SQLFunctionsTest.java index af6aaf2ee1..54c7db61dd 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/legacy/SQLFunctionsTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/legacy/SQLFunctionsTest.java @@ -15,6 +15,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import org.hibernate.dialect.DerbyDialect; import org.hibernate.dialect.TeradataDialect; import org.jboss.logging.Logger; import org.junit.Test; @@ -384,7 +385,7 @@ public class SQLFunctionsTest extends LegacyTestCase { simple.setName("Simple 1"); s.save( simple ); - if ( getDialect() instanceof DB2Dialect) { + if ( getDialect() instanceof DB2Dialect && !(getDialect() instanceof DerbyDialect) ) { s.createQuery( "from Simple s where repeat('foo', 3) = 'foofoofoo'" ).list(); s.createQuery( "from Simple s where repeat(s.name, 3) = 'foofoofoo'" ).list(); s.createQuery( "from Simple s where repeat( lower(s.name), 3 + (1-1) / 2) = 'foofoofoo'" ).list(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/legacy/SQLLoaderTest.java b/hibernate-core/src/test/java/org/hibernate/test/legacy/SQLLoaderTest.java index 18d91ae784..2348c3eddb 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/legacy/SQLLoaderTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/legacy/SQLLoaderTest.java @@ -98,7 +98,7 @@ public class SQLLoaderTest extends LegacyTestCase { Category s = new Category(); s.setName(String.valueOf(nextLong++)); - session.save(s); + session.save( s ); Simple simple = new Simple( Long.valueOf(nextLong++) ); simple.init(); @@ -108,7 +108,7 @@ public class SQLLoaderTest extends LegacyTestCase { session.save(a); B b = new B(); - session.save(b); + session.save( b ); session.flush(); session.createSQLQuery( "select {category.*} from category {category}" ).addEntity( "category", Category.class ).list(); @@ -128,17 +128,17 @@ public class SQLLoaderTest extends LegacyTestCase { } Category s = new Category(); - s.setName(String.valueOf(nextLong++)); - session.save(s); + s.setName( String.valueOf( nextLong++ ) ); + session.save( s ); s = new Category(); - s.setName("WannaBeFound"); + s.setName( "WannaBeFound" ); session.flush(); Query query = session.createSQLQuery( "select {category.*} from category {category} where {category}.name = :name" ) .addEntity( "category", Category.class ); - query.setProperties(s); + query.setProperties( s ); //query.setParameter("name", s.getName()); query.list(); @@ -146,7 +146,7 @@ public class SQLLoaderTest extends LegacyTestCase { query = session.createSQLQuery( "select {category.*} from category {category} where {category}.name in (:names)" ) .addEntity( "category", Category.class ); String[] str = new String[] { "WannaBeFound", "NotThere" }; - query.setParameterList("names", str); + query.setParameterList( "names", str ); query.uniqueResult(); query = session.createSQLQuery( "select {category.*} from category {category} where {category}.name in :names" ) @@ -157,12 +157,12 @@ public class SQLLoaderTest extends LegacyTestCase { query = session.createSQLQuery( "select {category.*} from category {category} where {category}.name in (:names)" ) .addEntity( "category", Category.class ); str = new String[] { "WannaBeFound" }; - query.setParameterList("names", str); + query.setParameterList( "names", str ); query.uniqueResult(); query = session.createSQLQuery( "select {category.*} from category {category} where {category}.name in :names" ) .addEntity( "category", Category.class ); - query.setParameterList("names", str); + query.setParameterList( "names", str ); query.uniqueResult(); session.getTransaction().commit(); @@ -402,10 +402,10 @@ public class SQLLoaderTest extends LegacyTestCase { } A savedA = new A(); savedA.setName("Max"); - session.save(savedA); + session.save( savedA ); B savedB = new B(); - session.save(savedB); + session.save( savedB ); session.flush(); int count = session.createQuery("from A").list().size(); @@ -429,7 +429,7 @@ public class SQLLoaderTest extends LegacyTestCase { List list = query.list(); assertNotNull(list); - assertEquals(1, list.size()); + assertEquals( 1, list.size() ); session.getTransaction().commit(); session.close(); } @@ -443,10 +443,10 @@ public class SQLLoaderTest extends LegacyTestCase { } A savedA = new A(); savedA.setName("Max"); - session.save(savedA); + session.save( savedA ); B savedB = new B(); - session.save(savedB); + session.save( savedB ); session.flush(); int count = session.createQuery("from A").list().size(); @@ -469,7 +469,7 @@ public class SQLLoaderTest extends LegacyTestCase { List list = query.list(); assertNotNull(list); - assertEquals(2, list.size()); + assertEquals( 2, list.size() ); session.getTransaction().commit(); session.close(); } @@ -556,12 +556,12 @@ public class SQLLoaderTest extends LegacyTestCase { session.beginTransaction(); SQLQuery q = session.createSQLQuery( sql ).addEntity( "comp", Componentizable.class ); List list = q.list(); - assertEquals(list.size(),1); + assertEquals( list.size(), 1 ); Componentizable co = (Componentizable) list.get(0); - assertEquals(c.getNickName(), co.getNickName()); - assertEquals(c.getComponent().getName(), co.getComponent().getName()); - assertEquals(c.getComponent().getSubComponent().getSubName(), co.getComponent().getSubComponent().getSubName()); + assertEquals( c.getNickName(), co.getNickName() ); + assertEquals( c.getComponent().getName(), co.getComponent().getName() ); + assertEquals( c.getComponent().getSubComponent().getSubName(), co.getComponent().getSubComponent().getSubName() ); session.delete( co ); session.getTransaction().commit(); @@ -573,16 +573,16 @@ public class SQLLoaderTest extends LegacyTestCase { session.beginTransaction(); Componentizable c = new Componentizable(); - c.setNickName("Flacky"); + c.setNickName( "Flacky" ); Component component = new Component(); component.setName("flakky comp"); SubComponent subComponent = new SubComponent(); subComponent.setSubName("subway"); - component.setSubComponent(subComponent); + component.setSubComponent( subComponent ); - c.setComponent(component); + c.setComponent( component ); - session.save(c); + session.save( c ); session.getTransaction().commit(); session.clear(); @@ -603,8 +603,8 @@ public class SQLLoaderTest extends LegacyTestCase { .addEntity( "category", Category.class ); List list = query.list(); - assertNotNull(list); - assertTrue(list.size() > 0); + assertNotNull( list ); + assertTrue( list.size() > 0 ); assertTrue(list.get(0) instanceof Category); session.getTransaction().commit(); session.close(); @@ -632,9 +632,9 @@ public class SQLLoaderTest extends LegacyTestCase { .addEntity( "category", Category.class ); List list = query.list(); - assertNotNull(list); - assertTrue(list.size() > 0); - assertTrue(list.get(0) instanceof Category); + assertNotNull( list ); + assertTrue( list.size() > 0 ); + assertTrue( list.get( 0 ) instanceof Category ); // How do we handle objects that does not have id property (such as Simple ?) // How do we handle objects with composite id's ? (such as Single) @@ -667,7 +667,7 @@ public class SQLLoaderTest extends LegacyTestCase { A a2 = (A) list.get(1); assertTrue((a2 instanceof B) || (a1 instanceof B)); - assertFalse(a1 instanceof B && a2 instanceof B); + assertFalse( a1 instanceof B && a2 instanceof B ); if (a1 instanceof B) { assertSame(a1, savedB); @@ -730,7 +730,7 @@ public class SQLLoaderTest extends LegacyTestCase { s.beginTransaction(); CompositeIdId id = new CompositeIdId(); id.setName("Max"); - id.setSystem("c64"); + id.setUser( "c64" ); id.setId("games"); s.save(id); s.getTransaction().commit(); @@ -741,13 +741,13 @@ public class SQLLoaderTest extends LegacyTestCase { // having a composite id with one property named id works since the map used by sqlloader to map names to properties handles it. // NOTE : SYSTEM is an ANSI SQL defined keyword, so it gets quoted; so it needs to get quoted here too String sql = String.format( - "select %1$s as {c.system}, " + + "select %1$s as {c.user}, " + " id as {c.id}, name as {c.name}, " + " foo as {c.composite.foo}, " + " bar as {c.composite.bar} " + "from CompositeIdId " + "where %1$s=? and id=?", - getDialect().openQuote() + "system" + getDialect().closeQuote() + getDialect().openQuote() + "user" + getDialect().closeQuote() ); SQLQuery query = s.createSQLQuery( sql ).addEntity( "c", CompositeIdId.class ); @@ -763,7 +763,7 @@ public class SQLLoaderTest extends LegacyTestCase { s = openSession(); s.beginTransaction(); CompositeIdId useForGet = new CompositeIdId(); - useForGet.setSystem("c64"); + useForGet.setUser( "c64" ); useForGet.setId("games"); // this doesn't work since the verification does not take column span into respect! CompositeIdId getted = (CompositeIdId) s.get(CompositeIdId.class, useForGet); @@ -776,7 +776,6 @@ public class SQLLoaderTest extends LegacyTestCase { assertEquals(id,id2); assertEquals(id.getName(), id2.getName()); assertEquals(id.getId(), id2.getId()); - assertEquals(id.getSystem(), id2.getSystem()); + assertEquals(id.getUser(), id2.getUser()); } - } diff --git a/hibernate-core/src/test/java/org/hibernate/test/ops/genericApi/BasicGetLoadAccessTest.java b/hibernate-core/src/test/java/org/hibernate/test/ops/genericApi/BasicGetLoadAccessTest.java index 1f0563d81b..321cf62dc6 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/ops/genericApi/BasicGetLoadAccessTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/ops/genericApi/BasicGetLoadAccessTest.java @@ -31,7 +31,7 @@ public class BasicGetLoadAccessTest extends BaseNonConfigCoreFunctionalTestCase } @Entity( name = "User" ) - @Table( name = "user" ) + @Table( name = "my_user" ) public static class User { private Integer id; private String name; diff --git a/hibernate-core/src/test/java/org/hibernate/test/ops/genericApi/ProxiedGetLoadAccessTest.java b/hibernate-core/src/test/java/org/hibernate/test/ops/genericApi/ProxiedGetLoadAccessTest.java index ec809614ce..59f9cf7a1a 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/ops/genericApi/ProxiedGetLoadAccessTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/ops/genericApi/ProxiedGetLoadAccessTest.java @@ -38,7 +38,7 @@ public class ProxiedGetLoadAccessTest extends BaseNonConfigCoreFunctionalTestCas } @Entity( name = "User" ) - @Table( name = "user" ) + @Table( name = "my_user" ) @Proxy( proxyClass = User.class ) public static class UserImpl implements User { private Integer id; diff --git a/hibernate-core/src/test/java/org/hibernate/test/optlock/Document.hbm.xml b/hibernate-core/src/test/java/org/hibernate/test/optlock/Document.hbm.xml index 78f9a49881..00473d672d 100755 --- a/hibernate-core/src/test/java/org/hibernate/test/optlock/Document.hbm.xml +++ b/hibernate-core/src/test/java/org/hibernate/test/optlock/Document.hbm.xml @@ -26,7 +26,7 @@ - + @@ -41,7 +41,7 @@ - + diff --git a/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/ForeignKeyMigrationTest.java b/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/ForeignKeyMigrationTest.java index e4af5cf193..6d3c14945f 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/ForeignKeyMigrationTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/ForeignKeyMigrationTest.java @@ -20,7 +20,10 @@ import org.hibernate.tool.hbm2ddl.SchemaExport; import org.hibernate.tool.hbm2ddl.SchemaUpdate; import org.hibernate.tool.hbm2ddl.Target; +import org.hibernate.testing.DialectCheck; +import org.hibernate.testing.DialectChecks; import org.hibernate.testing.FailureExpected; +import org.hibernate.testing.RequiresDialectFeature; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseUnitTestCase; import org.junit.Test; @@ -28,6 +31,7 @@ import org.junit.Test; /** * @author Steve Ebersole */ +@RequiresDialectFeature( value = {DialectChecks.SupportSchemaCreation.class, DialectChecks.SupportCatalogCreation.class}) public class ForeignKeyMigrationTest extends BaseUnitTestCase { @Test @TestForIssue( jiraKey = "HHH-9716" ) diff --git a/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/SchemaExportTest.java b/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/SchemaExportTest.java index e705ffee64..c642ab8c15 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/SchemaExportTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/SchemaExportTest.java @@ -124,7 +124,7 @@ public abstract class SchemaExportTest extends BaseUnitTestCase { assertEquals( 0, schemaExport.getExceptions().size() ); } else { - assertEquals( 2, schemaExport.getExceptions().size() ); + assertEquals( 1, schemaExport.getExceptions().size() ); } // call create again; it should drop tables before re-creating schemaExport.create( true, true ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/TestFkUpdating.java b/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/TestFkUpdating.java index 076cff7f2c..d754057c72 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/TestFkUpdating.java +++ b/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/TestFkUpdating.java @@ -11,6 +11,7 @@ import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.ManyToMany; +import javax.persistence.Table; import org.hibernate.annotations.GenericGenerator; import org.hibernate.boot.MetadataSources; @@ -67,6 +68,7 @@ public class TestFkUpdating { @Entity( name = "User" ) + @Table( name = "my_user") public static class User { private Integer id; private Set roles; diff --git a/hibernate-core/src/test/java/org/hibernate/test/sorted/SortTest.java b/hibernate-core/src/test/java/org/hibernate/test/sorted/SortTest.java index 3eed684d05..c0cadc70bd 100755 --- a/hibernate-core/src/test/java/org/hibernate/test/sorted/SortTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/sorted/SortTest.java @@ -15,6 +15,7 @@ import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; +import javax.persistence.Table; import org.hibernate.FetchMode; import org.hibernate.Hibernate; @@ -128,6 +129,7 @@ public class SortTest extends BaseCoreFunctionalTestCase { } @Entity + @Table(name = "Owner") private static class Owner { @Id @@ -140,6 +142,7 @@ public class SortTest extends BaseCoreFunctionalTestCase { } @Entity + @Table(name = "Cat") private static class Cat implements Comparable { @Id diff --git a/hibernate-core/src/test/java/org/hibernate/test/sql/hand/custom/CustomStoredProcTestSupport.java b/hibernate-core/src/test/java/org/hibernate/test/sql/hand/custom/CustomStoredProcTestSupport.java index 89838bf29e..a092381bde 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/sql/hand/custom/CustomStoredProcTestSupport.java +++ b/hibernate-core/src/test/java/org/hibernate/test/sql/hand/custom/CustomStoredProcTestSupport.java @@ -6,6 +6,8 @@ */ package org.hibernate.test.sql.hand.custom; +import java.sql.CallableStatement; +import java.sql.ResultSet; import java.sql.SQLException; import java.util.List; @@ -15,6 +17,8 @@ import org.hibernate.HibernateException; import org.hibernate.Query; import org.hibernate.Session; import org.hibernate.Transaction; +import org.hibernate.procedure.ProcedureCall; + import org.hibernate.test.sql.hand.Employment; import org.hibernate.test.sql.hand.Organization; import org.hibernate.test.sql.hand.Person; @@ -88,6 +92,4 @@ public abstract class CustomStoredProcTestSupport extends CustomSQLTestSupport { t.commit(); s.close(); } - - } diff --git a/hibernate-core/src/test/java/org/hibernate/test/sql/hand/custom/db2/DB2CustomSQLTest.java b/hibernate-core/src/test/java/org/hibernate/test/sql/hand/custom/db2/DB2CustomSQLTest.java index eb427976e6..5c68bf40ce 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/sql/hand/custom/db2/DB2CustomSQLTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/sql/hand/custom/db2/DB2CustomSQLTest.java @@ -7,8 +7,11 @@ package org.hibernate.test.sql.hand.custom.db2; import org.hibernate.dialect.DB2Dialect; +import org.hibernate.dialect.DerbyDialect; + import org.hibernate.test.sql.hand.custom.CustomStoredProcTestSupport; import org.hibernate.testing.RequiresDialect; +import org.hibernate.testing.SkipForDialect; /** * Custom SQL tests for DB2 @@ -16,6 +19,7 @@ import org.hibernate.testing.RequiresDialect; * @author Max Rydahl Andersen */ @RequiresDialect( DB2Dialect.class ) +@SkipForDialect( DerbyDialect.class ) public class DB2CustomSQLTest extends CustomStoredProcTestSupport { public String[] getMappings() { return new String[] { "sql/hand/custom/db2/Mappings.hbm.xml" }; diff --git a/hibernate-core/src/test/java/org/hibernate/test/sql/hand/custom/derby/DerbyCustomSQLTest.java b/hibernate-core/src/test/java/org/hibernate/test/sql/hand/custom/derby/DerbyCustomSQLTest.java new file mode 100644 index 0000000000..18310de028 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/sql/hand/custom/derby/DerbyCustomSQLTest.java @@ -0,0 +1,22 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.test.sql.hand.custom.derby; + +import org.hibernate.dialect.DerbyDialect; + +import org.hibernate.testing.RequiresDialect; +import org.hibernate.test.sql.hand.custom.CustomStoredProcTestSupport; + +/** + * @author Andrea Boriero + */ +@RequiresDialect(DerbyDialect.class) +public class DerbyCustomSQLTest extends CustomStoredProcTestSupport { + public String[] getMappings() { + return new String[] {"sql/hand/custom/derby/Mappings.hbm.xml"}; + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/sql/hand/custom/derby/DerbyStoreProcedures.java b/hibernate-core/src/test/java/org/hibernate/test/sql/hand/custom/derby/DerbyStoreProcedures.java new file mode 100644 index 0000000000..908d1f8fd3 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/sql/hand/custom/derby/DerbyStoreProcedures.java @@ -0,0 +1,52 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.test.sql.hand.custom.derby; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; + +/** + * @author Andrea Boriero + */ +public class DerbyStoreProcedures { + + public static void selectAllEmployments(ResultSet[] resultSets) throws SQLException { + Connection conn = DriverManager.getConnection( "jdbc:default:connection" ); + + PreparedStatement statement = conn.prepareStatement( + "select EMPLOYEE, EMPLOYER, STARTDATE, ENDDATE," + + " REGIONCODE, EMPID, 'VALUE', CURRENCY" + + " FROM EMPLOYMENT" + ); + resultSets[0] = statement.executeQuery(); + + conn.close(); + } + + public static void paramHandling(short j, short i, ResultSet[] resultSets) throws SQLException { + Connection conn = DriverManager.getConnection( "jdbc:default:connection" ); + + PreparedStatement statement = conn.prepareStatement( "SELECT " + j + " as value, " + i + " as value2 from sysibm.sysdummy1" ); + resultSets[0] = statement.executeQuery(); + + conn.close(); + } + + public static void simpleScalar(short i, ResultSet[] resultSets) throws SQLException { + Connection conn = DriverManager.getConnection( "jdbc:default:connection" ); + + PreparedStatement statement = conn.prepareStatement( + "SELECT " + i + " as value, 'getAll' as name from sysibm.sysdummy1" + ); + resultSets[0] = statement.executeQuery(); + + conn.close(); + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/sql/hand/custom/derby/Mappings.hbm.xml b/hibernate-core/src/test/java/org/hibernate/test/sql/hand/custom/derby/Mappings.hbm.xml new file mode 100644 index 0000000000..4fd21b937a --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/sql/hand/custom/derby/Mappings.hbm.xml @@ -0,0 +1,275 @@ + + + + + + + + + + + + + + + + + + + + INSERT INTO ORGANIZATION (NAME, ORGID) VALUES ( UPPER(? || ''), ? ) + UPDATE ORGANIZATION SET NAME=UPPER(? || '') WHERE ORGID=? + DELETE FROM ORGANIZATION WHERE ORGID=? + + + + + + + + + INSERT INTO PERSON (NAME, PERID) VALUES ( UPPER(? || ''), ? ) + UPDATE PERSON SET NAME=UPPER(? || '') WHERE PERID=? + DELETE FROM PERSON WHERE PERID=? + + + + + + + + + + + + + + + + + + INSERT INTO EMPLOYMENT + (EMPLOYEE, EMPLOYER, STARTDATE, REGIONCODE, VALUE, CURRENCY, EMPID) + + VALUES (?, ?, TIMESTAMP ('2006-02-28 11:39:00'), UPPER(? || ''), ?, ?, ?) + + UPDATE EMPLOYMENT SET ENDDATE=?, VALUE=?, CURRENCY=? WHERE EMPID=? + DELETE FROM EMPLOYMENT WHERE EMPID=? + + + + + + + + + + INSERT INTO TEXTHOLDER + (DESCRIPTION, ID) + VALUES (?, ?) + + UPDATE TEXTHOLDER SET DESCRIPTION=? WHERE ID=? + DELETE FROM TEXTHOLDER WHERE ID=? + + + + + + + + + + INSERT INTO IMAGEHOLDER + (PHOTO, ID) + VALUES (?, ?) + + UPDATE IMAGEHOLDER SET PHOTO=? WHERE ID=? + DELETE FROM IMAGEHOLDER WHERE ID=? + + + + + + + + + + + + + + + + + SELECT NAME AS {p.name}, PERID AS {p.id} FROM PERSON WHERE PERID=? /*FOR UPDATE*/ + + + + + + SELECT {org.*}, {emp.*} + FROM ORGANIZATION org + LEFT OUTER JOIN EMPLOYMENT emp ON org.ORGID = emp.EMPLOYER + WHERE org.ORGID=? + + + + + + + + SELECT DISTINCT org.NAME AS {org.name}, org.ORGID AS {org.id} + FROM ORGANIZATION org + INNER JOIN EMPLOYMENT e ON e.EMPLOYER = org.ORGID + + + + + + + + + SELECT EMPLOYEE AS {emp.employee}, EMPLOYER AS {emp.employer}, + STARTDATE AS {emp.startDate}, ENDDATE AS {emp.endDate}, + REGIONCODE as {emp.regionCode}, EMPID AS {emp.id} + FROM EMPLOYMENT + WHERE EMPID = ? + + + + + SELECT {empcol.*} + FROM EMPLOYMENT empcol + WHERE EMPLOYER = :id + ORDER BY STARTDATE ASC, EMPLOYEE ASC + + + + + + + + + + + + + + + SELECT EMPLOYEE AS {emp.employee}, EMPLOYER AS {emp.employer}, + STARTDATE AS {emp.startDate}, ENDDATE AS {emp.endDate}, + REGIONCODE as {emp.regionCode}, EMPID AS {emp.id}, VALUE, CURRENCY + FROM EMPLOYMENT + WHERE EMPLOYER = :id AND ENDDATE IS NULL + ORDER BY STARTDATE ASC + + + + + + { call simpleScalar(:number) } + + + + + + { call paramHandling(?,?) } + + + + + + { call paramHandling(?,:second) } + + + + + + + + + + + + + + + + + { call selectAllEmployments() } + + + + + SELECT ID AS {h.id}, DESCRIPTION AS {h.description} FROM TEXTHOLDER WHERE ID=? /*FOR UPDATE*/ + + + + + SELECT ID AS {h.id}, PHOTO AS {h.photo} FROM IMAGEHOLDER WHERE ID=? /*FOR UPDATE*/ + + + + + + CREATE PROCEDURE selectAllEmployments () + PARAMETER STYLE JAVA + LANGUAGE JAVA + READS SQL DATA + DYNAMIC RESULT SETS 2 + EXTERNAL NAME 'org.hibernate.test.sql.hand.custom.derby.DerbyStoreProcedures.selectAllEmployments' + + + DROP PROCEDURE selectAllEmployments + + + + + + + CREATE PROCEDURE paramHandling (j SMALLINT, i SMALLINT) + PARAMETER STYLE JAVA + LANGUAGE JAVA + READS SQL DATA + DYNAMIC RESULT SETS 2 + EXTERNAL NAME 'org.hibernate.test.sql.hand.custom.derby.DerbyStoreProcedures.paramHandling' + + + DROP PROCEDURE paramHandling + + + + + + CREATE PROCEDURE simpleScalar (j SMALLINT) + PARAMETER STYLE JAVA + LANGUAGE JAVA + READS SQL DATA + DYNAMIC RESULT SETS 2 + EXTERNAL NAME 'org.hibernate.test.sql.hand.custom.derby.DerbyStoreProcedures.simpleScalar' + + + DROP PROCEDURE simpleScalar + + + 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 182ccf812b..e431f91bd9 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 @@ -12,6 +12,7 @@ import java.util.List; import org.junit.Assert; import org.hibernate.Session; +import org.hibernate.dialect.DerbyDialect; import org.hibernate.dialect.H2Dialect; import org.hibernate.dialect.SQLServerDialect; import org.hibernate.dialect.SybaseDialect; @@ -27,7 +28,8 @@ import org.junit.Test; @SkipForDialects({ @SkipForDialect(value = H2Dialect.class, comment = "H2 doesn't support this sql syntax"), @SkipForDialect(value = SQLServerDialect.class, comment = "mssql doesn't support multiple columns in the 'where' clause of a 'where in' query"), - @SkipForDialect(value = SybaseDialect.class, comment = "sybase doesn't support multiple columns in the 'where' clause of a 'where in' query")}) + @SkipForDialect(value = SybaseDialect.class, comment = "sybase doesn't support multiple columns in the 'where' clause of a 'where in' query"), + @SkipForDialect(value = DerbyDialect.class, comment = "derby doesn't support multiple columns in the 'where' clause of a 'where in' query")}) @TestForIssue( jiraKey = "HHH-8312") public class CompositeIdTypeBindingTest extends BaseCoreFunctionalTestCase { @Override diff --git a/hibernate-core/src/test/java/org/hibernate/test/temporal/TimePropertyTest.java b/hibernate-core/src/test/java/org/hibernate/test/temporal/TimePropertyTest.java index 578addf3ad..d1814ac967 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/temporal/TimePropertyTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/temporal/TimePropertyTest.java @@ -12,6 +12,7 @@ import java.text.SimpleDateFormat; import java.util.Date; import javax.persistence.GeneratedValue; import javax.persistence.Id; +import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; @@ -81,6 +82,7 @@ public class TimePropertyTest extends BaseCoreFunctionalTestCase { } @javax.persistence.Entity + @Table(name = "entity") public static class Entity { @GeneratedValue @Id diff --git a/hibernate-core/src/test/java/org/hibernate/test/temporal/TimestampPropertyTest.java b/hibernate-core/src/test/java/org/hibernate/test/temporal/TimestampPropertyTest.java index 44c1333889..6dcff7d692 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/temporal/TimestampPropertyTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/temporal/TimestampPropertyTest.java @@ -12,6 +12,7 @@ import java.util.Date; import javax.persistence.Column; import javax.persistence.GeneratedValue; import javax.persistence.Id; +import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; @@ -140,6 +141,7 @@ public class TimestampPropertyTest extends BaseCoreFunctionalTestCase { } @javax.persistence.Entity + @Table(name = "MyEntity") public static class Entity { @GeneratedValue @Id diff --git a/hibernate-core/src/test/java/org/hibernate/test/tm/BeforeCompletionFailureTest.java b/hibernate-core/src/test/java/org/hibernate/test/tm/BeforeCompletionFailureTest.java index 7ba3969ac3..a1a4f71747 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/tm/BeforeCompletionFailureTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/tm/BeforeCompletionFailureTest.java @@ -127,7 +127,7 @@ public class BeforeCompletionFailureTest extends BaseNonConfigCoreFunctionalTest public static class SimpleEntity { @Id public Integer id; - @Column(unique = true) + @Column(unique = true, name = "entity_key") public String key; public String name; diff --git a/hibernate-core/src/test/java/org/hibernate/test/type/converter/ElementCollectionTests.java b/hibernate-core/src/test/java/org/hibernate/test/type/converter/ElementCollectionTests.java index 02346a00c7..155c0883ae 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/type/converter/ElementCollectionTests.java +++ b/hibernate-core/src/test/java/org/hibernate/test/type/converter/ElementCollectionTests.java @@ -160,7 +160,7 @@ public class ElementCollectionTests extends BaseNonConfigCoreFunctionalTestCase }) @ElementCollection(fetch = FetchType.LAZY) @CollectionTable(name = "entity_map", joinColumns = @JoinColumn(name = "entity_id", nullable = false)) - @MapKeyColumn(name = "key", nullable = false) + @MapKeyColumn(name = "map_key", nullable = false) @Column(name = "value", nullable = false) public Map map = new HashMap(); diff --git a/hibernate-core/src/test/resources/org/hibernate/test/annotations/xml/ejb3/orm.xml b/hibernate-core/src/test/resources/org/hibernate/test/annotations/xml/ejb3/orm.xml index bb084cbd1f..57e0064852 100644 --- a/hibernate-core/src/test/resources/org/hibernate/test/annotations/xml/ejb3/orm.xml +++ b/hibernate-core/src/test/resources/org/hibernate/test/annotations/xml/ejb3/orm.xml @@ -45,6 +45,7 @@ + DATE diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/cascade/DetachAndContainsTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/cascade/DetachAndContainsTest.java index b9290eac5f..dfcd9cb1c0 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/cascade/DetachAndContainsTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/cascade/DetachAndContainsTest.java @@ -14,6 +14,7 @@ import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; +import javax.persistence.Table; import org.junit.Test; @@ -72,6 +73,7 @@ public class DetachAndContainsTest extends BaseEntityManagerFunctionalTestCase { } @Entity + @Table(name = "mouth") public static class Mouth { @Id @GeneratedValue @@ -81,6 +83,7 @@ public class DetachAndContainsTest extends BaseEntityManagerFunctionalTestCase { } @Entity + @Table(name = "tooth") public static class Tooth { @Id @GeneratedValue diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/cdi/BasicCDITest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/cdi/BasicCDITest.java index 0f05d5ca3e..5fe8af7fa4 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/cdi/BasicCDITest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/cdi/BasicCDITest.java @@ -15,6 +15,7 @@ import javax.persistence.EntityListeners; import javax.persistence.EntityManager; import javax.persistence.Id; import javax.persistence.PrePersist; +import javax.persistence.Table; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; @@ -62,6 +63,7 @@ public class BasicCDITest extends BaseCDIIntegrationTest { @Entity @EntityListeners( Monitor.class ) + @Table(name = "my_entity") public static class MyEntity { private Integer id; private String name; diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/connection/DataSourceInjectionTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/connection/DataSourceInjectionTest.java index a5ea9d2d03..6a44daf8d0 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/connection/DataSourceInjectionTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/connection/DataSourceInjectionTest.java @@ -11,6 +11,7 @@ package org.hibernate.jpa.test.connection; import java.io.File; import javax.persistence.EntityManagerFactory; +import javax.persistence.PersistenceException; import org.hibernate.ejb.HibernatePersistence; @@ -37,10 +38,14 @@ public class DataSourceInjectionTest { emf.close(); } catch (Exception ignore) { + int i = 0; } } Assert.fail( "FakeDatasource should have been used" ); } + catch (PersistenceException pe) { + Assert.assertTrue( pe.getCause() instanceof FakeDataSourceException ); + } catch (FakeDataSourceException fde) { //success } diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/convert/QueryTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/convert/QueryTest.java index c655a79694..a5764deb4d 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/convert/QueryTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/convert/QueryTest.java @@ -7,6 +7,7 @@ package org.hibernate.jpa.test.convert; import javax.persistence.AttributeConverter; +import javax.persistence.Column; import javax.persistence.Converter; import javax.persistence.Embeddable; import javax.persistence.Embedded; @@ -86,8 +87,10 @@ public class QueryTest extends BaseEntityManagerFunctionalTestCase { @Embeddable public static class Name { + @Column(name = "first_name") public String first; public String middle; + @Column(name = "last_name") public String last; public Name() { diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/basic/CastTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/basic/CastTest.java index 341ca32e55..ca51660b14 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/basic/CastTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/basic/CastTest.java @@ -14,10 +14,12 @@ import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.Root; +import org.hibernate.dialect.DerbyDialect; import org.hibernate.jpa.test.metamodel.AbstractMetamodelSpecificTest; import org.hibernate.jpa.test.metamodel.Product; import org.hibernate.jpa.test.metamodel.Product_; +import org.hibernate.testing.SkipForDialect; import org.hibernate.testing.TestForIssue; import org.junit.Assert; import org.junit.Test; @@ -26,6 +28,7 @@ public class CastTest extends AbstractMetamodelSpecificTest { private static final int QUANTITY = 2; @Test + @SkipForDialect(value = DerbyDialect.class,comment = "Derby does not support cast from INTEGER to VARCHAR") @TestForIssue( jiraKey = "HHH-5755" ) public void testCastToString() { EntityManager em = getOrCreateEntityManager(); diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/enumcollection/User.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/enumcollection/User.java index 1204f34674..898d8077e8 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/enumcollection/User.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/enumcollection/User.java @@ -20,6 +20,7 @@ import java.util.HashSet; import java.util.Set; @Entity +@Table(name = "users") public class User { private Long id; private Set roles = new HashSet(); diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/selectcase/SelectCaseTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/selectcase/SelectCaseTest.java index 7d5b1d26f8..36cab9d007 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/selectcase/SelectCaseTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/criteria/selectcase/SelectCaseTest.java @@ -27,6 +27,7 @@ import javax.persistence.EntityManager; import javax.persistence.EnumType; import javax.persistence.Enumerated; import javax.persistence.Id; +import javax.persistence.Table; import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.Expression; @@ -121,6 +122,7 @@ public class SelectCaseTest extends BaseEntityManagerFunctionalTestCase { } @javax.persistence.Entity + @Table(name = "entity") public static class Entity { @Id diff --git a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/graphs/EntityGraphTest.java b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/graphs/EntityGraphTest.java index 6bacbd22ff..d0eb5d67b9 100644 --- a/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/graphs/EntityGraphTest.java +++ b/hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/graphs/EntityGraphTest.java @@ -19,6 +19,7 @@ import javax.persistence.Id; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.Subgraph; +import javax.persistence.Table; import org.hibernate.Hibernate; import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; @@ -248,6 +249,7 @@ public class EntityGraphTest extends BaseEntityManagerFunctionalTestCase { } @Entity + @Table(name = "foo") public static class Foo { @Id @@ -262,6 +264,7 @@ public class EntityGraphTest extends BaseEntityManagerFunctionalTestCase { } @Entity + @Table(name = "bar") public static class Bar { @Id @@ -273,6 +276,7 @@ public class EntityGraphTest extends BaseEntityManagerFunctionalTestCase { } @Entity + @Table(name = "baz") public static class Baz { @Id diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/sametable/BasicSametable.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/sametable/BasicSametable.java index 42fb1c4bda..784b1a5f09 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/sametable/BasicSametable.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/manytomany/sametable/BasicSametable.java @@ -51,8 +51,8 @@ public class BasicSametable extends BaseEnversJPAFunctionalTestCase { session.createSQLQuery( "DROP TABLE children" ).executeUpdate(); session.createSQLQuery( "CREATE TABLE children ( parent_id " + getDialect().getTypeName( Types.INTEGER ) + - ", child1_id " + getDialect().getTypeName( Types.INTEGER ) + " NULL" + - ", child2_id " + getDialect().getTypeName( Types.INTEGER ) + " NULL )" + ", child1_id " + getDialect().getTypeName( Types.INTEGER ) + getDialect().getNullColumnString() + + ", child2_id " + getDialect().getTypeName( Types.INTEGER ) + getDialect().getNullColumnString() + " )" ).executeUpdate(); session.createSQLQuery( "DROP TABLE children_AUD" ).executeUpdate(); session.createSQLQuery( @@ -60,8 +60,8 @@ public class BasicSametable extends BaseEnversJPAFunctionalTestCase { ", REVEND " + getDialect().getTypeName( Types.INTEGER ) + ", REVTYPE " + getDialect().getTypeName( Types.TINYINT ) + ", parent_id " + getDialect().getTypeName( Types.INTEGER ) + - ", child1_id " + getDialect().getTypeName( Types.INTEGER ) + " NULL" + - ", child2_id " + getDialect().getTypeName( Types.INTEGER ) + " NULL )" + ", child1_id " + getDialect().getTypeName( Types.INTEGER ) + getDialect().getNullColumnString() + + ", child2_id " + getDialect().getTypeName( Types.INTEGER ) + getDialect().getNullColumnString() + " )" ).executeUpdate(); em.getTransaction().commit(); em.clear(); diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/strategy/ValidityAuditStrategyRevEndTestCustomRevEnt.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/strategy/ValidityAuditStrategyRevEndTestCustomRevEnt.java index ef065b4a3e..09b88a8997 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/strategy/ValidityAuditStrategyRevEndTestCustomRevEnt.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/strategy/ValidityAuditStrategyRevEndTestCustomRevEnt.java @@ -78,8 +78,8 @@ public class ValidityAuditStrategyRevEndTestCustomRevEnt extends BaseEnversJPAFu session .createSQLQuery( "CREATE TABLE children ( parent_id " + getDialect().getTypeName( Types.INTEGER ) + - ", child1_id " + getDialect().getTypeName( Types.INTEGER ) + " NULL" + - ", child2_id " + getDialect().getTypeName( Types.INTEGER ) + " NULL )" + ", child1_id " + getDialect().getTypeName( Types.INTEGER ) + getDialect().getNullColumnString() + + ", child2_id " + getDialect().getTypeName( Types.INTEGER ) + getDialect().getNullColumnString() + " )" ) .executeUpdate(); session.createSQLQuery( "DROP TABLE children_AUD" ).executeUpdate(); @@ -90,8 +90,8 @@ public class ValidityAuditStrategyRevEndTestCustomRevEnt extends BaseEnversJPAFu ", " + revendTimestampColumName + " " + getDialect().getTypeName( Types.TIMESTAMP ) + ", REVTYPE " + getDialect().getTypeName( Types.TINYINT ) + ", parent_id " + getDialect().getTypeName( Types.INTEGER ) + - ", child1_id " + getDialect().getTypeName( Types.INTEGER ) + " NULL" + - ", child2_id " + getDialect().getTypeName( Types.INTEGER ) + " NULL )" + ", child1_id " + getDialect().getTypeName( Types.INTEGER ) + getDialect().getNullColumnString() + + ", child2_id " + getDialect().getTypeName( Types.INTEGER ) + getDialect().getNullColumnString() + " )" ) .executeUpdate(); em.getTransaction().commit(); diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/strategy/ValidityAuditStrategyRevEndTsTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/strategy/ValidityAuditStrategyRevEndTsTest.java index 939df2d5fd..0652bbb819 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/strategy/ValidityAuditStrategyRevEndTsTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/strategy/ValidityAuditStrategyRevEndTsTest.java @@ -77,8 +77,8 @@ public class ValidityAuditStrategyRevEndTsTest extends BaseEnversJPAFunctionalTe session .createSQLQuery( "CREATE TABLE children ( parent_id " + getDialect().getTypeName( Types.INTEGER ) + - ", child1_id " + getDialect().getTypeName( Types.INTEGER ) + " NULL" + - ", child2_id " + getDialect().getTypeName( Types.INTEGER ) + " NULL )" + ", child1_id " + getDialect().getTypeName( Types.INTEGER ) + getDialect().getNullColumnString() + + ", child2_id " + getDialect().getTypeName( Types.INTEGER ) + getDialect().getNullColumnString() + " )" ) .executeUpdate(); session.createSQLQuery( "DROP TABLE children_AUD" ).executeUpdate(); @@ -89,8 +89,8 @@ public class ValidityAuditStrategyRevEndTsTest extends BaseEnversJPAFunctionalTe ", " + revendTimestampColumName + " " + getDialect().getTypeName( Types.TIMESTAMP ) + ", REVTYPE " + getDialect().getTypeName( Types.TINYINT ) + ", parent_id " + getDialect().getTypeName( Types.INTEGER ) + - ", child1_id " + getDialect().getTypeName( Types.INTEGER ) + " NULL" + - ", child2_id " + getDialect().getTypeName( Types.INTEGER ) + " NULL )" + ", child1_id " + getDialect().getTypeName( Types.INTEGER ) + getDialect().getNullColumnString() + + ", child2_id " + getDialect().getTypeName( Types.INTEGER ) + getDialect().getNullColumnString() + " )" ) .executeUpdate(); em.getTransaction().commit(); 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 1526d28e3f..ab4ebf60bd 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/DialectChecks.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/DialectChecks.java @@ -165,4 +165,16 @@ abstract public class DialectChecks { return '\"' == dialect.openQuote() && '\"' == dialect.closeQuote(); } } + + public static class SupportSchemaCreation implements DialectCheck { + public boolean isMatch(Dialect dialect) { + return dialect.canCreateSchema(); + } + } + + public static class SupportCatalogCreation implements DialectCheck { + public boolean isMatch(Dialect dialect) { + return dialect.canCreateCatalog(); + } + } } diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseCoreFunctionalTestCase.java b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseCoreFunctionalTestCase.java index 62f4548560..03e3a7aae9 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseCoreFunctionalTestCase.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseCoreFunctionalTestCase.java @@ -18,6 +18,7 @@ import javax.persistence.SharedCacheMode; import org.hibernate.HibernateException; import org.hibernate.Interceptor; import org.hibernate.Session; +import org.hibernate.Transaction; import org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl; import org.hibernate.boot.registry.BootstrapServiceRegistry; import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder; @@ -35,6 +36,7 @@ import org.hibernate.internal.util.config.ConfigurationHelper; import org.hibernate.jdbc.AbstractReturningWork; import org.hibernate.jdbc.Work; import org.hibernate.resource.transaction.TransactionCoordinator; +import org.hibernate.resource.transaction.spi.TransactionStatus; import org.hibernate.testing.AfterClassOnce; import org.hibernate.testing.BeforeClassOnce; @@ -358,6 +360,7 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase { if ( tdc.getStatus().canRollback() ) { session.getTransaction().rollback(); } + session.close(); } protected void cleanupCache() { @@ -369,16 +372,24 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase { protected boolean isCleanupTestDataRequired() { return false; } - + protected void cleanupTestData() throws Exception { Session s = openSession(); - s.beginTransaction(); - s.createQuery( "delete from java.lang.Object" ).executeUpdate(); - s.getTransaction().commit(); - s.close(); + Transaction transaction = s.beginTransaction(); + try { + s.createQuery( "delete from java.lang.Object" ).executeUpdate(); + transaction.commit(); + } + catch (Exception e) { + if ( transaction.getStatus().canRollback() ) { + transaction.rollback(); + } + } + finally { + s.close(); + } } - private void cleanupSession() { if ( session != null && ! ( (SessionImplementor) session ).isClosed() ) { session.close(); @@ -405,7 +416,9 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase { } Session tmpSession = sessionFactory.openSession(); + Transaction transaction = tmpSession.beginTransaction(); try { + List list = tmpSession.createQuery( "select o from java.lang.Object o" ).list(); Map items = new HashMap(); @@ -419,11 +432,16 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase { items.put( tmpSession.getEntityName( element ), l ); System.out.println( "Data left: " + element ); } + transaction.rollback(); fail( "Data is left in the database: " + items.toString() ); } + transaction.rollback(); } finally { try { + if(transaction.getStatus().canRollback()){ + transaction.rollback(); + } tmpSession.close(); } catch( Throwable t ) { diff --git a/libraries.gradle b/libraries.gradle index 38d42557bf..13562f4cbe 100644 --- a/libraries.gradle +++ b/libraries.gradle @@ -81,7 +81,7 @@ ext { shrinkwrap_api: 'org.jboss.shrinkwrap:shrinkwrap-api:1.0.0-beta-6', shrinkwrap: 'org.jboss.shrinkwrap:shrinkwrap-impl-base:1.0.0-beta-6', h2: "com.h2database:h2:${h2Version}", - derby: "org.apache.derby:derby:10.9.1.0", + derby: "org.apache.derby:derby:10.11.1.1", jboss_jta: "org.jboss.jbossts:jbossjta:4.16.4.Final", xapool: "com.experlog:xapool:1.5.0", mockito: 'org.mockito:mockito-core:1.9.0',