/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/MixedFieldPropertyAnnotationTest.java

https://github.com/aleksabl/hibernate-core · Java · 110 lines · 70 code · 14 blank · 26 comment · 0 complexity · 43c85ea4e8cac24b4c8f14c9006e20ff MD5 · raw file

  1. /*
  2. * Hibernate, Relational Persistence for Idiomatic Java
  3. *
  4. * Copyright (c) {DATE}, Red Hat Inc. or third-party contributors as
  5. * indicated by the @author tags or express copyright attribution
  6. * statements applied by the authors. All third-party contributions are
  7. * distributed under license by Red Hat Inc.
  8. *
  9. * This copyrighted material is made available to anyone wishing to use, modify,
  10. * copy, or redistribute it subject to the terms and conditions of the GNU
  11. * Lesser General Public License, as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  15. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
  16. * for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public License
  19. * along with this distribution; if not, write to:
  20. * Free Software Foundation, Inc.
  21. * 51 Franklin Street, Fifth Floor
  22. * Boston, MA 02110-1301 USA
  23. */
  24. package org.hibernate.test.schemaupdate;
  25. import java.util.EnumSet;
  26. import javax.persistence.Column;
  27. import javax.persistence.Entity;
  28. import javax.persistence.Id;
  29. import javax.persistence.Table;
  30. import org.hibernate.boot.MetadataSources;
  31. import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
  32. import org.hibernate.boot.spi.MetadataImplementor;
  33. import org.hibernate.cfg.Environment;
  34. import org.hibernate.dialect.MySQLDialect;
  35. import org.hibernate.service.ServiceRegistry;
  36. import org.hibernate.tool.hbm2ddl.SchemaExport;
  37. import org.hibernate.tool.hbm2ddl.SchemaUpdate;
  38. import org.hibernate.tool.schema.TargetType;
  39. import org.hibernate.testing.RequiresDialect;
  40. import org.hibernate.testing.TestForIssue;
  41. import org.hibernate.testing.junit4.CustomRunner;
  42. import org.junit.After;
  43. import org.junit.Before;
  44. import org.junit.Test;
  45. import org.junit.runner.RunWith;
  46. /**
  47. * @author Andrea Boriero
  48. */
  49. @TestForIssue(jiraKey = "HHH-9849")
  50. @RunWith(CustomRunner.class)
  51. @RequiresDialect(MySQLDialect.class)
  52. public class MixedFieldPropertyAnnotationTest {
  53. protected ServiceRegistry serviceRegistry;
  54. protected MetadataImplementor metadata;
  55. @Test
  56. public void testUpdateSchema() throws Exception {
  57. new SchemaUpdate().execute( EnumSet.of( TargetType.STDOUT, TargetType.DATABASE ), metadata );
  58. }
  59. @Entity
  60. @Table(name = "MyEntity")
  61. class MyEntity {
  62. @Id
  63. public int getId() {
  64. return 0;
  65. }
  66. @Column(name = "Ul")
  67. public int getValue() {
  68. return 0;
  69. }
  70. public void setId(final int _id) {
  71. }
  72. public void setValue(int value) {
  73. }
  74. }
  75. @Before
  76. public void setUp() {
  77. serviceRegistry = new StandardServiceRegistryBuilder().applySetting(
  78. Environment.GLOBALLY_QUOTED_IDENTIFIERS,
  79. "false"
  80. ).build();
  81. metadata = (MetadataImplementor) new MetadataSources( serviceRegistry )
  82. .addAnnotatedClass( MyEntity.class )
  83. .buildMetadata();
  84. System.out.println( "********* Starting SchemaExport for START-UP *************************" );
  85. new SchemaExport().create( EnumSet.of( TargetType.STDOUT, TargetType.DATABASE ), metadata );
  86. System.out.println( "********* Completed SchemaExport for START-UP *************************" );
  87. }
  88. @After
  89. public void tearDown() {
  90. System.out.println( "********* Starting SchemaExport (drop) for TEAR-DOWN *************************" );
  91. new SchemaExport().drop( EnumSet.of( TargetType.STDOUT, TargetType.DATABASE ), metadata );
  92. System.out.println( "********* Completed SchemaExport (drop) for TEAR-DOWN *************************" );
  93. StandardServiceRegistryBuilder.destroy( serviceRegistry );
  94. serviceRegistry = null;
  95. }
  96. }