diff --git a/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/SchemaExportWithGlobalQuotingEnabledTest.java b/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/SchemaExportWithGlobalQuotingEnabledTest.java new file mode 100644 index 0000000000..ecc97b86e2 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/SchemaExportWithGlobalQuotingEnabledTest.java @@ -0,0 +1,143 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) {DATE}, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.test.schemaupdate; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.ManyToMany; +import javax.persistence.Table; +import java.sql.SQLException; +import java.util.List; +import java.util.Set; + +import org.hibernate.boot.MetadataSources; +import org.hibernate.boot.registry.StandardServiceRegistryBuilder; +import org.hibernate.boot.spi.MetadataImplementor; +import org.hibernate.cfg.Environment; +import org.hibernate.dialect.MySQLDialect; +import org.hibernate.service.ServiceRegistry; +import org.hibernate.tool.hbm2ddl.SchemaExport; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.hibernate.testing.RequiresDialect; +import org.hibernate.testing.TestForIssue; +import org.hibernate.testing.junit4.CustomRunner; + +import static org.hamcrest.core.IsNot.not; +import static org.junit.Assert.assertThat; + +/** + * @author Andrea Boriero + */ +@TestForIssue(jiraKey = "HHH-9866") +@RunWith(CustomRunner.class) +@RequiresDialect(MySQLDialect.class) +public class SchemaExportWithGlobalQuotingEnabledTest { + protected ServiceRegistry serviceRegistry; + protected MetadataImplementor metadata; + + @Test + public void testSchemaExport() throws Exception { + + SchemaExport schemaExport = new SchemaExport( serviceRegistry, metadata ); + schemaExport.create( true, true ); + + List exceptions = schemaExport.getExceptions(); + for ( SQLException exception : exceptions ) { + assertThat( exception.getMessage(), exception.getSQLState(), not( "42000" ) ); + } + } + + @Before + public void setUp() { + serviceRegistry = new StandardServiceRegistryBuilder().applySetting( + Environment.GLOBALLY_QUOTED_IDENTIFIERS, + "true" + ).build(); + metadata = (MetadataImplementor) new MetadataSources( serviceRegistry ) + .addAnnotatedClass( MyEntity.class ) + .addAnnotatedClass( Role.class ) + .buildMetadata(); + + System.out.println( "********* Starting SchemaExport for START-UP *************************" ); + SchemaExport schemaExport = new SchemaExport( serviceRegistry, metadata ); + schemaExport.create( true, true ); + System.out.println( "********* Completed SchemaExport for START-UP *************************" ); + } + + @After + public void tearDown() { + System.out.println( "********* Starting SchemaExport (drop) for TEAR-DOWN *************************" ); + SchemaExport schemaExport = new SchemaExport( serviceRegistry, metadata ); + schemaExport.drop( true, true ); + System.out.println( "********* Completed SchemaExport (drop) for TEAR-DOWN *************************" ); + + StandardServiceRegistryBuilder.destroy( serviceRegistry ); + serviceRegistry = null; + } + + @Entity + @Table(name = "MyEntity") + public static class MyEntity { + private int id; + private Set roles; + + @Id + public int getId() { + return this.id; + } + + public void setId(final int id) { + this.id = id; + } + + @ManyToMany + public Set getRoles() { + return roles; + } + + public void setRoles(Set roles) { + this.roles = roles; + } + } + + @Entity + public static class Role { + private Integer id; + + @Id + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + } + +}