|
|
|
|
|
|
With hibernate.globally_quoted_identifiers = true and Mysql, the schema export cause a SQL syntax
{code:java} @Entity @Table(name = "MyEntity") public class MyEntity { private int id; private Set<Role> roles; @Id public int getId() { return this.id; } public void setId(final int id) { this.id = id; }
@ManyToMany public Set<Role> getRoles() { return roles; }
public void setRoles(Set<Role> roles) { this.roles = roles; } } {code}
{code:java} @Entity public class Role { private Integer id;
@Id public Integer getId() { return id; }
public void setId(Integer id) { this.id = id; } } {code}
{code:java} public class MamyToManyWithGlobalQuotingAnnotationTest {
protected ServiceRegistry serviceRegistry; protected MetadataImplementor metadata;
@Test public void createSchema() throws Exception {
SchemaExport schemaExport = new SchemaExport( serviceRegistry, metadata ); schemaExport.create( true, true );
List<SQLException> exceptions = schemaExport.getExceptions(); for ( SQLException exception : exceptions ) { String sqlState = exception.getSQLState(); assertThat( sqlState, not( "42000" ) ); }
}
@Before public void setUp() { serviceRegistry = new StandardServiceRegistryBuilder().applySetting( Environment.GLOBALLY_QUOTED_IDENTIFIERS, "true" ).build(); metadata = (MetadataImplementor) new MetadataSources( serviceRegistry ) .addAnnotatedClass( MyEntityWithRoles 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; }
} {code}
cause the erro
RROR SchemaExport:478 - HHH000389: Unsuccessful: create table `MyEntity_Role` (*`MyEntity_`id``* integer not null, *`roles_`id``* integer not null, primary key (`MyEntity_`id``, `roles_`id``)) 18:34:01,904 ERROR SchemaExport:479 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'id`` integer not null, `roles_`id`` integer not null, primary ke' at line 2
|
|
|
|
|
|