|
| 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 | + |
| 26 | +import javax.persistence.Column; |
| 27 | +import javax.persistence.Entity; |
| 28 | +import javax.persistence.Id; |
| 29 | +import javax.persistence.Table; |
| 30 | + |
| 31 | +import org.hibernate.boot.MetadataSources; |
| 32 | +import org.hibernate.boot.registry.StandardServiceRegistryBuilder; |
| 33 | +import org.hibernate.boot.spi.MetadataImplementor; |
| 34 | +import org.hibernate.cfg.Environment; |
| 35 | +import org.hibernate.dialect.MySQLDialect; |
| 36 | +import org.hibernate.service.ServiceRegistry; |
| 37 | +import org.hibernate.tool.hbm2ddl.SchemaExport; |
| 38 | +import org.hibernate.tool.hbm2ddl.SchemaUpdate; |
| 39 | + |
| 40 | +import org.junit.After; |
| 41 | +import org.junit.Before; |
| 42 | +import org.junit.Test; |
| 43 | +import org.junit.runner.RunWith; |
| 44 | + |
| 45 | +import org.hibernate.testing.RequiresDialect; |
| 46 | +import org.hibernate.testing.TestForIssue; |
| 47 | +import org.hibernate.testing.junit4.CustomRunner; |
| 48 | + |
| 49 | +/** |
| 50 | + * @author Andrea Boriero |
| 51 | + */ |
| 52 | +@TestForIssue(jiraKey = "HHH-9849") |
| 53 | +@RunWith(CustomRunner.class) |
| 54 | +@RequiresDialect(MySQLDialect.class) |
| 55 | +public class MixedFieldPropertyAnnotationTest { |
| 56 | + protected ServiceRegistry serviceRegistry; |
| 57 | + protected MetadataImplementor metadata; |
| 58 | + |
| 59 | + @Test |
| 60 | + public void testUpdateSchema() throws Exception { |
| 61 | + |
| 62 | + |
| 63 | + new SchemaUpdate( |
| 64 | + metadata |
| 65 | + ).execute( true, true ); |
| 66 | + } |
| 67 | + |
| 68 | + @Entity |
| 69 | + @Table(name = "MyEntity") |
| 70 | + class MyEntity { |
| 71 | + |
| 72 | + @Id |
| 73 | + public int getId() { |
| 74 | + return 0; |
| 75 | + } |
| 76 | + |
| 77 | + @Column(name = "Ul") |
| 78 | + public int getValue() { |
| 79 | + return 0; |
| 80 | + } |
| 81 | + |
| 82 | + public void setId(final int _id) { |
| 83 | + } |
| 84 | + |
| 85 | + public void setValue(int value) { |
| 86 | + } |
| 87 | + } |
| 88 | + |
| 89 | + @Before |
| 90 | + public void setUp() { |
| 91 | + serviceRegistry = new StandardServiceRegistryBuilder().applySetting( |
| 92 | + Environment.GLOBALLY_QUOTED_IDENTIFIERS, |
| 93 | + "false" |
| 94 | + ).build(); |
| 95 | + metadata = (MetadataImplementor) new MetadataSources( serviceRegistry ) |
| 96 | + .addAnnotatedClass( MyEntity.class ) |
| 97 | + .buildMetadata(); |
| 98 | + |
| 99 | + System.out.println( "********* Starting SchemaExport for START-UP *************************" ); |
| 100 | + SchemaExport schemaExport = new SchemaExport( serviceRegistry, metadata ); |
| 101 | + schemaExport.create( true, true ); |
| 102 | + System.out.println( "********* Completed SchemaExport for START-UP *************************" ); |
| 103 | + } |
| 104 | + |
| 105 | + @After |
| 106 | + public void tearDown() { |
| 107 | + System.out.println( "********* Starting SchemaExport (drop) for TEAR-DOWN *************************" ); |
| 108 | + SchemaExport schemaExport = new SchemaExport( serviceRegistry, metadata ); |
| 109 | + schemaExport.drop( true, true ); |
| 110 | + System.out.println( "********* Completed SchemaExport (drop) for TEAR-DOWN *************************" ); |
| 111 | + |
| 112 | + StandardServiceRegistryBuilder.destroy( serviceRegistry ); |
| 113 | + serviceRegistry = null; |
| 114 | + } |
| 115 | +} |
0 commit comments