HHH-10691 - Fix tests failing when switching to PostgreSQL

HHH-10696 - Add a new CatalogFilterTest
This commit is contained in:
Vlad Mihalcea 2016-04-18 17:58:16 +03:00 committed by Andrea Boriero
parent a8deb5f1e0
commit da347c6d0c
22 changed files with 442 additions and 135 deletions

View File

@ -16,6 +16,7 @@ import javax.persistence.Id;
import javax.persistence.Lob;
import org.hibernate.Session;
import org.hibernate.engine.jdbc.BlobProxy;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.junit.Test;
@ -49,8 +50,7 @@ public class BlobTest extends BaseEntityManagerFunctionalTestCase {
product.setName( "Mobile phone" );
session.doWork( connection -> {
product.setImage( connection.createBlob() );
product.getImage().setBytes( 1, image );
product.setImage( BlobProxy.generateProxy( image ) );
} );
entityManager.persist( product );

View File

@ -16,6 +16,7 @@ import javax.persistence.Id;
import javax.persistence.Lob;
import org.hibernate.Session;
import org.hibernate.engine.jdbc.ClobProxy;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.junit.Test;
@ -49,8 +50,7 @@ public class ClobTest extends BaseEntityManagerFunctionalTestCase {
product.setName( "Mobile phone" );
session.doWork( connection -> {
product.setWarranty( connection.createClob() );
product.getWarranty().setString( 1, warranty );
product.setWarranty( ClobProxy.generateProxy( warranty ) );
} );
entityManager.persist( product );

View File

@ -11,8 +11,11 @@ import javax.persistence.Id;
import javax.persistence.Lob;
import org.hibernate.annotations.Nationalized;
import org.hibernate.dialect.MySQL5Dialect;
import org.hibernate.dialect.PostgreSQL81Dialect;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.SkipForDialect;
import org.junit.Test;
import static org.hibernate.userguide.util.TransactionUtil.doInJPA;
@ -21,6 +24,13 @@ import static org.junit.Assert.assertArrayEquals;
/**
* @author Vlad Mihalcea
*/
@SkipForDialect(
value = {
PostgreSQL81Dialect.class,
MySQL5Dialect.class
},
comment = "@see https://hibernate.atlassian.net/browse/HHH-10693 and https://hibernate.atlassian.net/browse/HHH-10695"
)
public class NClobCharArrayTest extends BaseEntityManagerFunctionalTestCase {
@Override

View File

@ -11,8 +11,11 @@ import javax.persistence.Id;
import javax.persistence.Lob;
import org.hibernate.annotations.Nationalized;
import org.hibernate.dialect.MySQL5Dialect;
import org.hibernate.dialect.PostgreSQL81Dialect;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.SkipForDialect;
import org.junit.Test;
import static org.hibernate.userguide.util.TransactionUtil.doInJPA;
@ -21,6 +24,13 @@ import static org.junit.Assert.assertEquals;
/**
* @author Vlad Mihalcea
*/
@SkipForDialect(
value = {
PostgreSQL81Dialect.class,
MySQL5Dialect.class
},
comment = "@see https://hibernate.atlassian.net/browse/HHH-10693 and https://hibernate.atlassian.net/browse/HHH-10695"
)
public class NClobStringTest extends BaseEntityManagerFunctionalTestCase {
@Override

View File

@ -17,8 +17,11 @@ import javax.persistence.Lob;
import org.hibernate.Session;
import org.hibernate.annotations.Nationalized;
import org.hibernate.dialect.MySQL5Dialect;
import org.hibernate.dialect.PostgreSQL81Dialect;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.SkipForDialect;
import org.junit.Test;
import static org.hibernate.userguide.util.TransactionUtil.doInJPA;
@ -28,6 +31,13 @@ import static org.junit.Assert.fail;
/**
* @author Vlad Mihalcea
*/
@SkipForDialect(
value = {
PostgreSQL81Dialect.class,
MySQL5Dialect.class
},
comment = "@see https://hibernate.atlassian.net/browse/HHH-10693 and https://hibernate.atlassian.net/browse/HHH-10695"
)
public class NClobTest extends BaseEntityManagerFunctionalTestCase {
@Override

View File

@ -10,8 +10,10 @@ import javax.persistence.Entity;
import javax.persistence.Id;
import org.hibernate.annotations.Nationalized;
import org.hibernate.dialect.PostgreSQL81Dialect;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.SkipForDialect;
import org.junit.Test;
import static org.hibernate.userguide.util.TransactionUtil.doInJPA;
@ -20,6 +22,12 @@ import static org.junit.Assert.assertEquals;
/**
* @author Vlad Mihalcea
*/
@SkipForDialect(
value = {
PostgreSQL81Dialect.class
},
comment = "@see https://hibernate.atlassian.net/browse/HHH-10693"
)
public class NationalizedTest extends BaseEntityManagerFunctionalTestCase {
@Override

View File

@ -7,10 +7,14 @@
package org.hibernate.userguide.multitenancy;
import org.hibernate.MultiTenancyStrategy;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.testing.RequiresDialect;
/**
* @author Vlad Mihalcea
*/
@RequiresDialect( value = H2Dialect.class)
public class DatabaseMultiTenancyTest extends AbstractMultiTenancyTest {
@Override

View File

@ -7,10 +7,14 @@
package org.hibernate.userguide.multitenancy;
import org.hibernate.MultiTenancyStrategy;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.testing.RequiresDialect;
/**
* @author Vlad Mihalcea
*/
@RequiresDialect( value = H2Dialect.class)
public class SchemaMultiTenancyTest extends AbstractMultiTenancyTest {
public static final String SCHEMA_TOKEN = ";INIT=CREATE SCHEMA IF NOT EXISTS %1$s\\;SET SCHEMA %1$s";

View File

@ -34,9 +34,14 @@ public class PersisterClassProviderTest extends BaseUnitTestCase {
.applySettings( cfg.getProperties() )
.build();
//no exception as the GoofyPersisterClassProvider is not set
SessionFactory sessionFactory = cfg.buildSessionFactory( serviceRegistry );
sessionFactory.close();
StandardServiceRegistryBuilder.destroy( serviceRegistry );
SessionFactory sessionFactory;
try {
sessionFactory = cfg.buildSessionFactory( serviceRegistry );
sessionFactory.close();
}
finally {
StandardServiceRegistryBuilder.destroy( serviceRegistry );
}
serviceRegistry = new StandardServiceRegistryBuilder()
.applySettings( cfg.getProperties() )

View File

@ -22,6 +22,7 @@ import org.hibernate.cfg.AvailableSettings;
import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.dialect.MySQL5Dialect;
import org.hibernate.dialect.PostgreSQL81Dialect;
import org.hibernate.dialect.PostgreSQL94Dialect;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.tool.schema.Action;
@ -29,6 +30,7 @@ import org.hibernate.type.PostgresUUIDType;
import org.hibernate.type.Type;
import org.hibernate.type.UUIDBinaryType;
import org.hibernate.testing.SkipForDialect;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.junit.Test;
@ -40,6 +42,7 @@ import static org.junit.Assert.assertThat;
* @author Steve Ebersole
*/
public class UUIDBasedIdInterpretationTest extends BaseUnitTestCase {
@Test
@TestForIssue( jiraKey = "HHH-10564")
public void testH2() {
@ -100,6 +103,7 @@ public class UUIDBasedIdInterpretationTest extends BaseUnitTestCase {
@Test
@TestForIssue( jiraKey = "HHH-10564")
@SkipForDialect(PostgreSQL81Dialect.class)
public void testBinaryRuntimeUsage() {
StandardServiceRegistry ssr = buildStandardServiceRegistry( H2Dialect.class, true );
try {

View File

@ -0,0 +1,242 @@
package org.hibernate.test.schemafilter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import javax.persistence.Entity;
import javax.persistence.Id;
import org.hibernate.boot.Metadata;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.model.naming.Identifier;
import org.hibernate.boot.model.relational.Namespace;
import org.hibernate.boot.model.relational.Sequence;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Environment;
import org.hibernate.dialect.SQLServerDialect;
import org.hibernate.mapping.Table;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.tool.schema.internal.DefaultSchemaFilter;
import org.hibernate.tool.schema.internal.SchemaCreatorImpl;
import org.hibernate.tool.schema.internal.SchemaDropperImpl;
import org.hibernate.tool.schema.spi.SchemaFilter;
import org.hibernate.testing.DialectChecks;
import org.hibernate.testing.RequiresDialectFeature;
import org.hibernate.testing.ServiceRegistryBuilder;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.junit.Assert;
import org.junit.Test;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import static org.hibernate.test.schemafilter.RecordingTarget.Category.TABLE_CREATE;
import static org.hibernate.test.schemafilter.RecordingTarget.Category.TABLE_DROP;
@SuppressWarnings({"rawtypes", "unchecked"})
@RequiresDialectFeature( value = {DialectChecks.SupportCatalogCreation.class})
public class CatalogFilterTest extends BaseUnitTestCase {
private final ServiceRegistry serviceRegistry;
private final Metadata metadata;
public CatalogFilterTest() {
Map settings = new HashMap();
settings.putAll( Environment.getProperties() );
settings.put( AvailableSettings.DIALECT, SQLServerDialect.class.getName() );
settings.put( AvailableSettings.FORMAT_SQL, false );
this.serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( settings );
MetadataSources ms = new MetadataSources( serviceRegistry );
ms.addAnnotatedClass( CatalogNoneEntity0.class );
ms.addAnnotatedClass( Catalog1Entity1.class );
ms.addAnnotatedClass( Catalog1Entity2.class );
ms.addAnnotatedClass( Catalog2Entity3.class );
ms.addAnnotatedClass( Catalog2Entity4.class );
this.metadata = ms.buildMetadata();
}
@Test
public void createCatalog_unfiltered() {
RecordingTarget target = doCreation( new DefaultSchemaFilter() );
Assert.assertThat( target.getActions( TABLE_CREATE ), containsExactly(
"the_entity_0",
"the_catalog_1.the_entity_1",
"the_catalog_1.the_entity_2",
"the_catalog_2.the_entity_3",
"the_catalog_2.the_entity_4"
) );
}
@Test
public void createCatalog_filtered() {
RecordingTarget target = doCreation( new TestSchemaFilter() );
Assert.assertThat(
target.getActions( TABLE_CREATE ),
containsExactly( "the_entity_0", "the_catalog_1.the_entity_1" )
);
}
@Test
public void dropCatalog_unfiltered() {
RecordingTarget target = doDrop( new DefaultSchemaFilter() );
Assert.assertThat( target.getActions( TABLE_DROP ), containsExactly(
"the_entity_0",
"the_catalog_1.the_entity_1",
"the_catalog_1.the_entity_2",
"the_catalog_2.the_entity_3",
"the_catalog_2.the_entity_4"
) );
}
@Test
public void dropCatalog_filtered() {
RecordingTarget target = doDrop( new TestSchemaFilter() );
Assert.assertThat(
target.getActions( TABLE_DROP ),
containsExactly( "the_entity_0", "the_catalog_1.the_entity_1" )
);
}
private RecordingTarget doCreation(SchemaFilter filter) {
RecordingTarget target = new RecordingTarget();
new SchemaCreatorImpl( serviceRegistry, filter ).doCreation( metadata, true, target );
return target;
}
private RecordingTarget doDrop(SchemaFilter filter) {
RecordingTarget target = new RecordingTarget();
new SchemaDropperImpl( serviceRegistry, filter ).doDrop( metadata, true, target );
return target;
}
private BaseMatcher<Set<String>> containsExactly(Object... expected) {
return containsExactly( new HashSet( Arrays.asList( expected ) ) );
}
private BaseMatcher<Set<String>> containsExactly(final Set expected) {
return new BaseMatcher<Set<String>>() {
@Override
public boolean matches(Object item) {
Set set = (Set) item;
return set.size() == expected.size()
&& set.containsAll( expected );
}
@Override
public void describeTo(Description description) {
description.appendText( "Is set containing exactly " + expected );
}
};
}
private static class TestSchemaFilter implements SchemaFilter {
@Override
public boolean includeNamespace(Namespace namespace) {
// exclude schema "the_catalog_2"
Identifier identifier = namespace.getName().getCatalog();
return identifier == null || !"the_catalog_2".equals( identifier.getText() );
}
@Override
public boolean includeTable(Table table) {
// exclude table "the_entity_2"
return !"the_entity_2".equals( table.getName() );
}
@Override
public boolean includeSequence(Sequence sequence) {
return true;
}
}
@Entity
@javax.persistence.Table(name = "the_entity_1", catalog = "the_catalog_1")
public static class Catalog1Entity1 {
@Id
private long id;
public long getId() {
return id;
}
public void setId( long id ) {
this.id = id;
}
}
@Entity
@javax.persistence.Table(name = "the_entity_2", catalog = "the_catalog_1")
public static class Catalog1Entity2 {
@Id
private long id;
public long getId() {
return id;
}
public void setId( long id ) {
this.id = id;
}
}
@Entity
@javax.persistence.Table(name = "the_entity_3", catalog = "the_catalog_2")
public static class Catalog2Entity3 {
@Id
private long id;
public long getId() {
return id;
}
public void setId( long id ) {
this.id = id;
}
}
@Entity
@javax.persistence.Table(name = "the_entity_4", catalog = "the_catalog_2")
public static class Catalog2Entity4 {
@Id
private long id;
public long getId() {
return id;
}
public void setId( long id ) {
this.id = id;
}
}
@Entity
@javax.persistence.Table(name = "the_entity_0")
public static class CatalogNoneEntity0 {
@Id
private long id;
public long getId() {
return id;
}
public void setId( long id ) {
this.id = id;
}
}
}

View File

@ -1,21 +0,0 @@
package org.hibernate.test.schemafilter;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "the_entity_1", schema = "the_schema_1")
public class Schema1Entity1 {
@Id
private long id;
public long getId() {
return id;
}
public void setId( long id ) {
this.id = id;
}
}

View File

@ -1,21 +0,0 @@
package org.hibernate.test.schemafilter;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "the_entity_2", schema = "the_schema_1")
public class Schema1Entity2 {
@Id
private long id;
public long getId() {
return id;
}
public void setId( long id ) {
this.id = id;
}
}

View File

@ -1,21 +0,0 @@
package org.hibernate.test.schemafilter;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "the_entity_3", schema = "the_schema_2")
public class Schema2Entity3 {
@Id
private long id;
public long getId() {
return id;
}
public void setId( long id ) {
this.id = id;
}
}

View File

@ -1,21 +0,0 @@
package org.hibernate.test.schemafilter;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "the_entity_4", schema = "the_schema_2")
public class Schema2Entity4 {
@Id
private long id;
public long getId() {
return id;
}
public void setId( long id ) {
this.id = id;
}
}

View File

@ -6,6 +6,9 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import javax.persistence.Entity;
import javax.persistence.Id;
import org.hibernate.boot.Metadata;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.model.naming.Identifier;
@ -21,6 +24,8 @@ import org.hibernate.tool.schema.internal.SchemaCreatorImpl;
import org.hibernate.tool.schema.internal.SchemaDropperImpl;
import org.hibernate.tool.schema.spi.SchemaFilter;
import org.hibernate.testing.DialectChecks;
import org.hibernate.testing.RequiresDialectFeature;
import org.hibernate.testing.ServiceRegistryBuilder;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseUnitTestCase;
@ -37,6 +42,7 @@ import static org.hibernate.test.schemafilter.RecordingTarget.Category.TABLE_DRO
@TestForIssue(jiraKey = "HHH-9876")
@SuppressWarnings({"rawtypes", "unchecked"})
@RequiresDialectFeature( value = {DialectChecks.SupportSchemaCreation.class})
public class SchemaFilterTest extends BaseUnitTestCase {
private final ServiceRegistry serviceRegistry;
@ -164,4 +170,85 @@ public class SchemaFilterTest extends BaseUnitTestCase {
return true;
}
}
@Entity
@javax.persistence.Table(name = "the_entity_1", schema = "the_schema_1")
public static class Schema1Entity1 {
@Id
private long id;
public long getId() {
return id;
}
public void setId( long id ) {
this.id = id;
}
}
@Entity
@javax.persistence.Table(name = "the_entity_2", schema = "the_schema_1")
public static class Schema1Entity2 {
@Id
private long id;
public long getId() {
return id;
}
public void setId( long id ) {
this.id = id;
}
}
@Entity
@javax.persistence.Table(name = "the_entity_3", schema = "the_schema_2")
public static class Schema2Entity3 {
@Id
private long id;
public long getId() {
return id;
}
public void setId( long id ) {
this.id = id;
}
}
@Entity
@javax.persistence.Table(name = "the_entity_4", schema = "the_schema_2")
public static class Schema2Entity4 {
@Id
private long id;
public long getId() {
return id;
}
public void setId( long id ) {
this.id = id;
}
}
@Entity
@javax.persistence.Table(name = "the_entity_0")
public static class SchemaNoneEntity0 {
@Id
private long id;
public long getId() {
return id;
}
public void setId( long id ) {
this.id = id;
}
}
}

View File

@ -1,22 +0,0 @@
package org.hibernate.test.schemafilter;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "the_entity_0")
public class SchemaNoneEntity0 {
@Id
private long id;
public long getId() {
return id;
}
public void setId( long id ) {
this.id = id;
}
}

View File

@ -3,6 +3,7 @@ package org.hibernate.test.schemaupdate;
import java.io.File;
import java.nio.file.Files;
import java.util.EnumSet;
import java.util.regex.Pattern;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@ -12,7 +13,6 @@ import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.boot.spi.MetadataImplementor;
import org.hibernate.cfg.Environment;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.tool.hbm2ddl.SchemaUpdate;
import org.hibernate.tool.schema.TargetType;
@ -30,10 +30,10 @@ import org.junit.Test;
public class SchemaUpdateFormatterTest {
private static final String AFTER_FORMAT =
"\n create table test_entity (\n" +
" field varchar(255) not null,\n" +
" primary key (field)\n" +
" );\n";
"\n\\s+create table test_entity \\(\n" +
"\\s+field varchar\\(255\\) not null,\n" +
"\\s+primary key \\(field\\)\n" +
"\\s+\\).*?;\n";
private static final String DELIMITER = ";";
@Test
@ -63,7 +63,7 @@ public class SchemaUpdateFormatterTest {
//On Windows, \r\n would become \n\n, so we eliminate duplicates
outputContent = outputContent.replaceAll( "\n\n", "\n");
Assert.assertEquals( AFTER_FORMAT, outputContent );
Assert.assertTrue( Pattern.compile( AFTER_FORMAT ).matcher( outputContent ).matches() );
}
finally {
StandardServiceRegistryBuilder.destroy( ssr );

View File

@ -49,6 +49,8 @@ public class SchemaUpdateWithFunctionIndexTest extends BaseNonConfigCoreFunction
@Before
public void setUp() {
dropFunctionIndex();
dropTable();
createTable();
createFunctionIndex();
serviceRegistry = new StandardServiceRegistryBuilder()
@ -78,15 +80,13 @@ public class SchemaUpdateWithFunctionIndexTest extends BaseNonConfigCoreFunction
session.close();
}
@After
public void tearDown() {
dropFunctionIndex();
System.out.println( "********* Starting SchemaExport (drop) for TEAR-DOWN *************************" );
new SchemaExport().drop( EnumSet.of( TargetType.DATABASE, TargetType.SCRIPT ), metadata );
System.out.println( "********* Completed SchemaExport (drop) for TEAR-DOWN *************************" );
StandardServiceRegistryBuilder.destroy( serviceRegistry );
serviceRegistry = null;
private void dropTable() {
Session session = openSession();
Transaction transaction = session.beginTransaction();
Query query = session.createSQLQuery( "DROP TABLE IF EXISTS MyEntity;" );
query.executeUpdate();
transaction.commit();
session.close();
}
private void dropFunctionIndex() {
@ -98,6 +98,14 @@ public class SchemaUpdateWithFunctionIndexTest extends BaseNonConfigCoreFunction
session.close();
}
@After
public void tearDown() {
dropFunctionIndex();
dropTable();
new SchemaExport().drop( EnumSet.of( TargetType.DATABASE, TargetType.STDOUT ), metadata );
StandardServiceRegistryBuilder.destroy( serviceRegistry );
}
@Entity
@Table(name = "MyEntity", indexes = @Index(columnList = "otherInfo"))
public static class MyEntity {

View File

@ -6,6 +6,7 @@
*/
package org.hibernate.test.schemaupdate;
import java.io.IOException;
import java.util.EnumSet;
import javax.persistence.Entity;
import javax.persistence.Id;
@ -38,16 +39,17 @@ import org.junit.Test;
@TestForIssue(jiraKey = "HHH-1872")
@RequiresDialect(PostgreSQL81Dialect.class)
public class SchemaUpdateWithViewsTest extends BaseNonConfigCoreFunctionalTestCase {
protected ServiceRegistry serviceRegistry;
protected MetadataImplementor metadata;
@Test
public void testUpdateSchema() {
new SchemaUpdate().execute( EnumSet.of( TargetType.SCRIPT, TargetType.DATABASE ), metadata );
new SchemaUpdate().execute( EnumSet.of( TargetType.DATABASE, TargetType.STDOUT ), metadata );
}
@Before
public void setUp() {
public void setUp() throws IOException {
createViewWithSameNameOfEntityTable();
serviceRegistry = new StandardServiceRegistryBuilder()
.applySetting( Environment.GLOBALLY_QUOTED_IDENTIFIERS, "false" )
@ -56,12 +58,13 @@ public class SchemaUpdateWithViewsTest extends BaseNonConfigCoreFunctionalTestCa
metadata = (MetadataImplementor) new MetadataSources( serviceRegistry )
.addAnnotatedClass( MyEntity.class )
.buildMetadata();
metadata.validate();
}
private void createViewWithSameNameOfEntityTable() {
Session session = openSession();
Transaction transaction = session.beginTransaction();
Query query = session.createSQLQuery( "CREATE VIEW MyEntity AS SELECT 'Hello World' " );
Query query = session.createSQLQuery( "CREATE OR REPLACE VIEW MyEntity AS SELECT 'Hello World' " );
query.executeUpdate();
transaction.commit();
session.close();
@ -81,7 +84,7 @@ public class SchemaUpdateWithViewsTest extends BaseNonConfigCoreFunctionalTestCa
private void dropView() {
Session session = openSession();
Transaction transaction = session.beginTransaction();
Query query = session.createSQLQuery( "DROP VIEW MyEntity " );
Query query = session.createSQLQuery( "DROP VIEW IF EXISTS MyEntity " );
query.executeUpdate();
transaction.commit();
session.close();

View File

@ -31,7 +31,6 @@ import org.hibernate.tool.schema.internal.ExceptionHandlerLoggedImpl;
import org.hibernate.tool.schema.internal.HibernateSchemaManagementTool;
import org.hibernate.tool.schema.internal.SchemaDropperImpl;
import org.hibernate.tool.schema.internal.SchemaMigratorImpl;
import org.hibernate.test.tool.schema.TargetDatabaseImpl;
import org.hibernate.tool.schema.internal.exec.GenerationTarget;
import org.hibernate.tool.schema.internal.exec.GenerationTargetToStdout;
import org.hibernate.tool.schema.spi.ExceptionHandler;
@ -42,6 +41,7 @@ import org.hibernate.tool.schema.spi.SourceDescriptor;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.hibernate.test.tool.schema.TargetDatabaseImpl;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@ -87,7 +87,7 @@ public class CrossSchemaForeignKeyGenerationTest extends BaseUnitTestCase {
final List<String> sqlLines = Files.readAllLines( output.toPath(), Charset.defaultCharset() );
assertThat(
"Expected alter table SCHEMA1.Child add constraint but is : " + sqlLines.get( 4 ),
sqlLines.get( 4 ).startsWith( "alter table " ),
sqlLines.get( sqlLines.size() - 1 ).startsWith( "alter table " ),
is( true )
);
}

View File

@ -16,6 +16,7 @@ import java.time.OffsetTime;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
import java.util.Iterator;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@ -92,14 +93,32 @@ public class Java8DateTimeTests extends BaseNonConfigCoreFunctionalTestCase {
@Entity(name = "TheEntity")
@Table(name="the_entity")
public static class TheEntity {
@Id
private Integer id;
@Column(name = "local_date_time")
private LocalDateTime localDateTime = LocalDateTime.now();
@Column(name = "local_date")
private LocalDate localDate = LocalDate.now();
@Column(name = "local_time")
private LocalTime localTime = LocalTime.now();
@Column(name = "instant_value")
private Instant instant = Instant.now();
@Column(name = "zoned_date_time")
private ZonedDateTime zonedDateTime = ZonedDateTime.now();
@Column(name = "offset_date_time")
private OffsetDateTime offsetDateTime = OffsetDateTime.now();
@Column(name = "offset_time")
private OffsetTime offsetTime = OffsetTime.now();
@Column(name = "duration_value")
private Duration duration = Duration.of( 20, ChronoUnit.DAYS );
public TheEntity() {
@ -109,7 +128,6 @@ public class Java8DateTimeTests extends BaseNonConfigCoreFunctionalTestCase {
this.id = id;
}
@Id
public Integer getId() {
return id;
}