HHH-11236 - JPA hbm2ddl auto-generation creates ddl with invalid syntax for Unique Key with any MySQLDialect

Add replicating test case that works just fine
This commit is contained in:
Vlad Mihalcea 2017-01-09 16:07:52 +02:00
parent 2a441d7f2d
commit 8f5bc492e8
2 changed files with 83 additions and 1 deletions

View File

@ -0,0 +1,82 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.test.annotations.uniqueconstraint;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.PersistenceException;
import javax.persistence.Table;
import org.hibernate.exception.ConstraintViolationException;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
/**
* @author Vlad Mihalcea
*/
@TestForIssue(jiraKey = "HHH-11236")
public class UniqueConstraintThrowsConstraintViolationExceptionTest extends BaseCoreFunctionalTestCase {
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class[] { Customer.class };
}
@Test
public void testUniqueConstraintWithEmptyColumnName() {
doInHibernate( this::sessionFactory, session -> {
Customer customer1 = new Customer();
customer1.customerId = "123";
session.persist( customer1 );
} );
try {
doInHibernate( this::sessionFactory, session -> {
Customer customer1 = new Customer();
customer1.customerId = "123";
session.persist( customer1 );
} );
fail( "Should throw" );
}
catch ( PersistenceException e ) {
assertEquals(
ConstraintViolationException.class,
e.getCause().getClass()
);
}
}
@Entity
@Table(name = "CUSTOMER")
public static class Customer {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "CUSTOMER_ACCOUNT_NUMBER")
public Long customerAccountNumber;
@Basic
@Column(name = "CUSTOMER_ID", unique = true)
public String customerId;
@Basic
@Column(name = "BILLING_ADDRESS")
public String billingAddress;
public Customer() {
}
}
}

View File

@ -95,7 +95,7 @@ ext {
hsqldb: "org.hsqldb:hsqldb:2.3.2", hsqldb: "org.hsqldb:hsqldb:2.3.2",
derby: "org.apache.derby:derby:10.11.1.1", derby: "org.apache.derby:derby:10.11.1.1",
postgresql: 'org.postgresql:postgresql:9.4-1202-jdbc41', postgresql: 'org.postgresql:postgresql:9.4-1202-jdbc41',
mysql: 'mysql:mysql-connector-java:5.1.38', mysql: 'mysql:mysql-connector-java:6.0.5',
mariadb: 'org.mariadb.jdbc:mariadb-java-client:1.1.7', mariadb: 'org.mariadb.jdbc:mariadb-java-client:1.1.7',
oracle: 'com.oracle.ojdbc:ojdbc7:12.1.0.2.0', oracle: 'com.oracle.ojdbc:ojdbc7:12.1.0.2.0',
mssql: 'com.microsoft.sqlserver:mssql-jdbc:6.1.0.jre8', mssql: 'com.microsoft.sqlserver:mssql-jdbc:6.1.0.jre8',