HHH-10879 SqlServer dialect doesn't respect "key" reserved keyword

This commit is contained in:
Marvin Froeder 2016-06-22 17:05:41 +12:00 committed by Vlad Mihalcea
parent a9318ce656
commit 74e959f1bc
5 changed files with 219 additions and 200 deletions

View File

@ -55,6 +55,7 @@ public class SQLServerDialect extends AbstractTransactSQLDialect {
registerFunction( "trim", new AnsiTrimEmulationFunction() ); registerFunction( "trim", new AnsiTrimEmulationFunction() );
registerKeyword( "top" ); registerKeyword( "top" );
registerKeyword( "key" );
this.limitHandler = new TopLimitHandler( false, false ); this.limitHandler = new TopLimitHandler( false, false );
} }

View File

@ -74,7 +74,7 @@ public class NormalizingIdentifierHelperImpl implements IdentifierHelper {
} }
if ( autoQuoteKeywords && isReservedWord( identifier.getText() ) ) { if ( autoQuoteKeywords && isReservedWord( identifier.getText() ) ) {
log.tracef( "Forcing identifier [%s] to quoted as recognized reserveed word", identifier ); log.tracef( "Forcing identifier [%s] to quoted as recognized reserved word", identifier );
return Identifier.toIdentifier( identifier.getText(), true ); return Identifier.toIdentifier( identifier.getText(), true );
} }

View File

@ -13,7 +13,6 @@ import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import javax.persistence.Table;
/** /**
* @author Guenther Demetz * @author Guenther Demetz

View File

@ -6,32 +6,43 @@
*/ */
package org.hibernate.test.dialect.functional; package org.hibernate.test.dialect.functional;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.sql.Connection; import java.sql.Connection;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import javax.persistence.Entity;
import javax.persistence.Id;
import org.hibernate.LockMode; import org.hibernate.LockMode;
import org.hibernate.LockOptions; import org.hibernate.LockOptions;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.Transaction; import org.hibernate.Transaction;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Configuration;
import org.hibernate.criterion.Order; import org.hibernate.criterion.Order;
import org.hibernate.criterion.Projections; import org.hibernate.criterion.Projections;
import org.hibernate.dialect.SQLServer2005Dialect; import org.hibernate.dialect.SQLServer2005Dialect;
import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.exception.LockTimeoutException; import org.hibernate.exception.LockTimeoutException;
import org.hibernate.jdbc.ReturningWork; import org.hibernate.jdbc.ReturningWork;
import org.hibernate.testing.RequiresDialect; import org.hibernate.testing.RequiresDialect;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/** /**
* used driver hibernate.connection.driver_class com.microsoft.sqlserver.jdbc.SQLServerDriver * used driver hibernate.connection.driver_class com.microsoft.sqlserver.jdbc.SQLServerDriver
* *
@ -39,41 +50,48 @@ import org.junit.Test;
*/ */
@RequiresDialect(value = { SQLServer2005Dialect.class }) @RequiresDialect(value = { SQLServer2005Dialect.class })
public class SQLServerDialectTest extends BaseCoreFunctionalTestCase { public class SQLServerDialectTest extends BaseCoreFunctionalTestCase {
private final ExecutorService executorService = Executors.newSingleThreadExecutor();
@Override
protected Configuration constructConfiguration() {
Configuration configuration = super.constructConfiguration();
configuration.setProperty( AvailableSettings.KEYWORD_AUTO_QUOTING_ENABLED, Boolean.TRUE.toString() );
return configuration;
}
@Test @Test
@TestForIssue(jiraKey = "HHH-7198") @TestForIssue(jiraKey = "HHH-7198")
public void testMaxResultsSqlServerWithCaseSensitiveCollation() throws Exception { public void testMaxResultsSqlServerWithCaseSensitiveCollation() throws Exception {
final Session s = openSession(); final Session s1 = openSession();
s.beginTransaction(); s1.beginTransaction();
String defaultCollationName = s.doReturningWork( new ReturningWork<String>() { String defaultCollationName = s1.doReturningWork( connection -> {
@Override String databaseName = connection.getCatalog();
public String execute(Connection connection) throws SQLException { Statement st = ((SessionImplementor)s1).getJdbcCoordinator().getStatementPreparer().createStatement();
String databaseName = connection.getCatalog(); ResultSet rs = ((SessionImplementor)s1).getJdbcCoordinator().getResultSetReturn().extract( st, "SELECT collation_name FROM sys.databases WHERE name = '"+databaseName+ "';" );
Statement st = ((SessionImplementor)s).getJdbcCoordinator().getStatementPreparer().createStatement(); while(rs.next()){
ResultSet rs = ((SessionImplementor)s).getJdbcCoordinator().getResultSetReturn().extract( st, "SELECT collation_name FROM sys.databases WHERE name = '"+databaseName+ "';" ); return rs.getString( "collation_name" );
while(rs.next()){
return rs.getString( "collation_name" );
}
throw new AssertionError( "can't get collation name of database "+databaseName );
} }
throw new AssertionError( "can't get collation name of database "+databaseName );
} ); } );
s.getTransaction().commit(); s1.getTransaction().commit();
s.close(); s1.close();
Session s2 = openSession(); Session s2 = openSession();
Transaction tx = s2.beginTransaction();
String databaseName = s2.doReturningWork( new ReturningWork<String>() { String databaseName = s2.doReturningWork( new ReturningWork<String>() {
@Override @Override
public String execute(Connection connection) throws SQLException { public String execute(Connection connection) throws SQLException {
return connection.getCatalog(); return connection.getCatalog();
} }
} ); } );
s2.createSQLQuery( "ALTER DATABASE " + databaseName + " set single_user with rollback immediate" ) s2.createNativeQuery( "ALTER DATABASE " + databaseName + " set single_user with rollback immediate" )
.executeUpdate(); .executeUpdate();
s2.createSQLQuery( "ALTER DATABASE " + databaseName + " COLLATE Latin1_General_CS_AS" ).executeUpdate(); s2.createNativeQuery( "ALTER DATABASE " + databaseName + " COLLATE Latin1_General_CS_AS" ).executeUpdate();
s2.createSQLQuery( "ALTER DATABASE " + databaseName + " set multi_user" ).executeUpdate(); s2.createNativeQuery( "ALTER DATABASE " + databaseName + " set multi_user" ).executeUpdate();
Transaction tx = s2.beginTransaction();
for ( int i = 1; i <= 20; i++ ) { for ( int i = 1; i <= 20; i++ ) {
s2.persist( new Product2( i, "Kit" + i ) ); s2.persist( new Product2( i, "Kit" + i ) );
@ -89,213 +107,183 @@ public class SQLServerDialectTest extends BaseCoreFunctionalTestCase {
tx.rollback(); tx.rollback();
s2.close(); s2.close();
s2 = openSession(); executorService.execute( () -> {
s2.createSQLQuery( "ALTER DATABASE " + databaseName + " set single_user with rollback immediate" ) doInHibernate( this::sessionFactory, s3 -> {
.executeUpdate(); s3.createNativeQuery( "ALTER DATABASE " + databaseName + " set single_user with rollback immediate" )
s2.createSQLQuery( "ALTER DATABASE " + databaseName + " COLLATE " + defaultCollationName ).executeUpdate(); .executeUpdate();
s2.createSQLQuery( "ALTER DATABASE " + databaseName + " set multi_user" ).executeUpdate(); s3.createNativeQuery( "ALTER DATABASE " + databaseName + " COLLATE " + defaultCollationName ).executeUpdate();
s2.close(); s3.createNativeQuery( "ALTER DATABASE " + databaseName + " set multi_user" ).executeUpdate();
} } );
} );
private void doWork(Session s) {
} }
@Test @Test
@TestForIssue(jiraKey = "HHH-7369") @TestForIssue(jiraKey = "HHH-7369")
public void testPaginationWithScalarQuery() throws Exception { public void testPaginationWithScalarQuery() throws Exception {
Session s = openSession(); doInHibernate( this::sessionFactory, session -> {
Transaction tx = s.beginTransaction(); for ( int i = 0; i < 10; i++ ) {
session.persist( new Product2( i, "Kit" + i ) );
}
session.flush();
session.clear();
for ( int i = 0; i < 10; i++ ) { List list = session.createNativeQuery( "select id from Product2 where description like 'Kit%' order by id" ).list();
s.persist( new Product2( i, "Kit" + i ) ); assertEquals(Integer.class, list.get(0).getClass()); // scalar result is an Integer
}
s.flush();
s.clear();
List list = s.createSQLQuery( "select id from Product2 where description like 'Kit%' order by id" ).list(); list = session.createNativeQuery( "select id from Product2 where description like 'Kit%' order by id" ).setFirstResult( 2 ).setMaxResults( 2 ).list();
assertEquals(Integer.class, list.get(0).getClass()); // scalar result is an Integer assertEquals(Integer.class, list.get(0).getClass()); // this fails without patch, as result suddenly has become an array
list = s.createSQLQuery( "select id from Product2 where description like 'Kit%' order by id" ).setFirstResult( 2 ).setMaxResults( 2 ).list(); // same once again with alias
assertEquals(Integer.class, list.get(0).getClass()); // this fails without patch, as result suddenly has become an array list = session.createNativeQuery( "select id as myint from Product2 where description like 'Kit%' order by id asc" ).setFirstResult( 2 ).setMaxResults( 2 ).list();
assertEquals(Integer.class, list.get(0).getClass());
// same once again with alias } );
list = s.createSQLQuery( "select id as myint from Product2 where description like 'Kit%' order by id asc" ).setFirstResult( 2 ).setMaxResults( 2 ).list();
assertEquals(Integer.class, list.get(0).getClass());
tx.rollback();
s.close();
} }
@Test @Test
@TestForIssue(jiraKey = "HHH-7368") @TestForIssue(jiraKey = "HHH-7368")
public void testPaginationWithTrailingSemicolon() throws Exception { public void testPaginationWithTrailingSemicolon() throws Exception {
Session s = openSession(); doInHibernate( this::sessionFactory, session -> {
s.createSQLQuery( "select id from Product2 where description like 'Kit%' order by id;" ) session.createNativeQuery( "select id from Product2 where description like 'Kit%' order by id;" )
.setFirstResult( 2 ).setMaxResults( 2 ).list(); .setFirstResult( 2 ).setMaxResults( 2 ).list();
s.close(); } );
} }
@Test @Test
public void testPaginationWithHQLProjection() { public void testPaginationWithHQLProjection() {
Session session = openSession(); doInHibernate( this::sessionFactory, session -> {
Transaction tx = session.beginTransaction(); for ( int i = 10; i < 20; i++ ) {
session.persist( new Product2( i, "Kit" + i ) );
}
session.flush();
session.clear();
for ( int i = 10; i < 20; i++ ) { List list = session.createQuery(
session.persist( new Product2( i, "Kit" + i ) ); "select id, description as descr, (select max(id) from Product2) as maximum from Product2"
} ).setFirstResult( 2 ).setMaxResults( 2 ).list();
session.flush(); assertEquals( 19, ( (Object[]) list.get( 1 ) )[2] );
session.clear();
List list = session.createQuery( list = session.createQuery( "select id, description, (select max(id) from Product2) from Product2 order by id" )
"select id, description as descr, (select max(id) from Product2) as maximum from Product2" .setFirstResult( 2 ).setMaxResults( 2 ).list();
).setFirstResult( 2 ).setMaxResults( 2 ).list(); assertEquals( 2, list.size() );
assertEquals( 19, ( (Object[]) list.get( 1 ) )[2] ); assertArrayEquals( new Object[] {12, "Kit12", 19}, (Object[]) list.get( 0 ));
assertArrayEquals( new Object[] {13, "Kit13", 19}, (Object[]) list.get( 1 ));
list = session.createQuery( "select id, description, (select max(id) from Product2) from Product2 order by id" ) } );
.setFirstResult( 2 ).setMaxResults( 2 ).list();
assertEquals( 2, list.size() );
assertArrayEquals( new Object[] {12, "Kit12", 19}, (Object[]) list.get( 0 ));
assertArrayEquals( new Object[] {13, "Kit13", 19}, (Object[]) list.get( 1 ));
tx.rollback();
session.close();
} }
@Test @Test
public void testPaginationWithHQL() { public void testPaginationWithHQL() {
Session session = openSession(); doInHibernate( this::sessionFactory, session -> {
Transaction tx = session.beginTransaction(); for ( int i = 20; i < 30; i++ ) {
session.persist( new Product2( i, "Kit" + i ) );
}
session.flush();
session.clear();
for ( int i = 20; i < 30; i++ ) { List list = session.createQuery( "from Product2 order by id" ).setFirstResult( 3 ).setMaxResults( 2 ).list();
session.persist( new Product2( i, "Kit" + i ) ); assertEquals( Arrays.asList( new Product2( 23, "Kit23" ), new Product2( 24, "Kit24" ) ), list );
} } );
session.flush();
session.clear();
List list = session.createQuery( "from Product2 order by id" ).setFirstResult( 3 ).setMaxResults( 2 ).list();
assertEquals( Arrays.asList( new Product2( 23, "Kit23" ), new Product2( 24, "Kit24" ) ), list );
tx.rollback();
session.close();
} }
@Test @Test
@TestForIssue(jiraKey = "HHH-7370") @TestForIssue(jiraKey = "HHH-7370")
public void testPaginationWithMaxOnly() { public void testPaginationWithMaxOnly() {
Session session = openSession(); doInHibernate( this::sessionFactory, session -> {
Transaction tx = session.beginTransaction(); for ( int i = 30; i < 40; i++ ) {
session.persist( new Product2( i, "Kit" + i ) );
}
session.flush();
session.clear();
for ( int i = 30; i < 40; i++ ) { List list = session.createQuery( "from Product2 order by id" ).setFirstResult( 0 ).setMaxResults( 2 ).list();
session.persist( new Product2( i, "Kit" + i ) ); assertEquals( Arrays.asList( new Product2( 30, "Kit30" ), new Product2( 31, "Kit31" ) ), list );
}
session.flush();
session.clear();
List list = session.createQuery( "from Product2 order by id" ).setFirstResult( 0 ).setMaxResults( 2 ).list(); list = session.createQuery( "select distinct p from Product2 p order by p.id" ).setMaxResults( 1 ).list();
assertEquals( Arrays.asList( new Product2( 30, "Kit30" ), new Product2( 31, "Kit31" ) ), list ); assertEquals( Collections.singletonList( new Product2( 30, "Kit30" ) ), list );
} );
list = session.createQuery( "select distinct p from Product2 p order by p.id" ).setMaxResults( 1 ).list();
assertEquals( Arrays.asList( new Product2( 30, "Kit30" ) ), list );
tx.rollback();
session.close();
} }
@Test @Test
@TestForIssue(jiraKey = "HHH-6627") @TestForIssue(jiraKey = "HHH-6627")
public void testPaginationWithAggregation() { public void testPaginationWithAggregation() {
Session session = openSession(); doInHibernate( this::sessionFactory, session -> {
Transaction tx = session.beginTransaction(); // populating test data
Category category1 = new Category( 1, "Category1" );
Category category2 = new Category( 2, "Category2" );
Category category3 = new Category( 3, "Category3" );
session.persist( category1 );
session.persist( category2 );
session.persist( category3 );
session.flush();
session.persist( new Product2( 1, "Kit1", category1 ) );
session.persist( new Product2( 2, "Kit2", category1 ) );
session.persist( new Product2( 3, "Kit3", category1 ) );
session.persist( new Product2( 4, "Kit4", category2 ) );
session.persist( new Product2( 5, "Kit5", category2 ) );
session.persist( new Product2( 6, "Kit6", category3 ) );
session.flush();
session.clear();
// populating test data // count number of products in each category
Category category1 = new Category( 1, "Category1" ); List<Object[]> result = session.createCriteria( Category.class, "c" ).createAlias( "products", "p" )
Category category2 = new Category( 2, "Category2" ); .setProjection(
Category category3 = new Category( 3, "Category3" ); Projections.projectionList()
session.persist( category1 ); .add( Projections.groupProperty( "c.id" ) )
session.persist( category2 ); .add( Projections.countDistinct( "p.id" ) )
session.persist( category3 ); )
session.flush(); .addOrder( Order.asc( "c.id" ) )
session.persist( new Product2( 1, "Kit1", category1 ) ); .setFirstResult( 1 ).setMaxResults( 3 ).list();
session.persist( new Product2( 2, "Kit2", category1 ) );
session.persist( new Product2( 3, "Kit3", category1 ) );
session.persist( new Product2( 4, "Kit4", category2 ) );
session.persist( new Product2( 5, "Kit5", category2 ) );
session.persist( new Product2( 6, "Kit6", category3 ) );
session.flush();
session.clear();
// count number of products in each category assertEquals( 2, result.size() );
List<Object[]> result = session.createCriteria( Category.class, "c" ).createAlias( "products", "p" ) assertArrayEquals( new Object[] { 2, 2L }, result.get( 0 ) ); // two products of second category
.setProjection( assertArrayEquals( new Object[] { 3, 1L }, result.get( 1 ) ); // one products of third category
Projections.projectionList() } );
.add( Projections.groupProperty( "c.id" ) )
.add( Projections.countDistinct( "p.id" ) )
)
.addOrder( Order.asc( "c.id" ) )
.setFirstResult( 1 ).setMaxResults( 3 ).list();
assertEquals( 2, result.size() );
assertArrayEquals( new Object[] { 2, 2L }, result.get( 0 ) ); // two products of second category
assertArrayEquals( new Object[] { 3, 1L }, result.get( 1 ) ); // one products of third category
tx.rollback();
session.close();
} }
@Test @Test
@TestForIssue(jiraKey = "HHH-7752") @TestForIssue(jiraKey = "HHH-7752")
public void testPaginationWithFormulaSubquery() { public void testPaginationWithFormulaSubquery() {
Session session = openSession(); doInHibernate( this::sessionFactory, session -> {
Transaction tx = session.beginTransaction(); // populating test data
Folder folder1 = new Folder( 1L, "Folder1" );
Folder folder2 = new Folder( 2L, "Folder2" );
Folder folder3 = new Folder( 3L, "Folder3" );
session.persist( folder1 );
session.persist( folder2 );
session.persist( folder3 );
session.flush();
session.persist( new Contact( 1L, "Lukasz", "Antoniak", "owner", folder1 ) );
session.persist( new Contact( 2L, "Kinga", "Mroz", "co-owner", folder2 ) );
session.flush();
session.clear();
session.refresh( folder1 );
session.refresh( folder2 );
session.clear();
// populating test data List<Long> folderCount = session.createQuery( "select count(distinct f) from Folder f" ).setMaxResults( 1 ).list();
Folder folder1 = new Folder( 1L, "Folder1" ); assertEquals( Arrays.asList( 3L ), folderCount );
Folder folder2 = new Folder( 2L, "Folder2" );
Folder folder3 = new Folder( 3L, "Folder3" );
session.persist( folder1 );
session.persist( folder2 );
session.persist( folder3 );
session.flush();
session.persist( new Contact( 1L, "Lukasz", "Antoniak", "owner", folder1 ) );
session.persist( new Contact( 2L, "Kinga", "Mroz", "co-owner", folder2 ) );
session.flush();
session.clear();
session.refresh( folder1 );
session.refresh( folder2 );
session.clear();
List<Long> folderCount = session.createQuery( "select count(distinct f) from Folder f" ).setMaxResults( 1 ).list(); List<Folder> distinctFolders = session.createQuery( "select distinct f from Folder f order by f.id desc" )
assertEquals( Arrays.asList( 3L ), folderCount ); .setFirstResult( 1 ).setMaxResults( 2 ).list();
assertEquals( Arrays.asList( folder2, folder1 ), distinctFolders );
List<Folder> distinctFolders = session.createQuery( "select distinct f from Folder f order by f.id desc" ) } );
.setFirstResult( 1 ).setMaxResults( 2 ).list();
assertEquals( Arrays.asList( folder2, folder1 ), distinctFolders );
tx.rollback();
session.close();
} }
@Test @Test
@TestForIssue(jiraKey = "HHH-7781") @TestForIssue(jiraKey = "HHH-7781")
public void testPaginationWithCastOperator() { public void testPaginationWithCastOperator() {
Session session = openSession(); doInHibernate( this::sessionFactory, session -> {
Transaction tx = session.beginTransaction(); for ( int i = 40; i < 50; i++ ) {
session.persist( new Product2( i, "Kit" + i ) );
}
session.flush();
session.clear();
for ( int i = 40; i < 50; i++ ) { List<Object[]> list = session.createQuery( "select p.id, cast(p.id as string) as string_id from Product2 p order by p.id" )
session.persist( new Product2( i, "Kit" + i ) ); .setFirstResult( 1 ).setMaxResults( 2 ).list();
} assertEquals( 2, list.size() );
session.flush(); assertArrayEquals( new Object[] { 41, "41" }, list.get( 0 ) );
session.clear(); assertArrayEquals( new Object[] { 42, "42" }, list.get( 1 ) );
} );
List<Object[]> list = session.createQuery( "select p.id, cast(p.id as string) as string_id from Product2 p order by p.id" )
.setFirstResult( 1 ).setMaxResults( 2 ).list();
assertEquals( 2, list.size() );
assertArrayEquals( new Object[] { 41, "41" }, list.get( 0 ) );
assertArrayEquals( new Object[] { 42, "42" }, list.get( 1 ) );
tx.rollback();
session.close();
} }
@Test @Test
@ -309,30 +297,22 @@ public class SQLServerDialectTest extends BaseCoreFunctionalTestCase {
kit.description = "m"; kit.description = "m";
s.persist( kit ); s.persist( kit );
s.getTransaction().commit(); s.getTransaction().commit();
final Transaction tx = s.beginTransaction();
final Transaction tx = s.beginTransaction();
Session s2 = openSession(); Session s2 = openSession();
Transaction tx2 = s2.beginTransaction(); s2.beginTransaction();
Product2 kit2 = (Product2) s2.byId( Product2.class ).load( kit.id ); Product2 kit2 = s2.byId( Product2.class ).load( kit.id );
kit.description = "change!"; kit.description = "change!";
s.flush(); // creates write lock on kit until we end the transaction s.flush(); // creates write lock on kit until we end the transaction
Thread thread = new Thread( Thread thread = new Thread(
new Runnable() { () -> {
@Override sleep( TimeUnit.SECONDS.toMillis( 1 ) );
public void run() { tx.commit();
try {
Thread.sleep( 3000 );
}
catch ( InterruptedException e ) {
e.printStackTrace();
}
tx.commit();
}
} }
); );
@ -348,10 +328,10 @@ public class SQLServerDialectTest extends BaseCoreFunctionalTestCase {
} }
long end = System.currentTimeMillis(); long end = System.currentTimeMillis();
thread.join(); thread.join();
long differenceInMillisecs = end - start; long differenceInMillis = end - start;
assertTrue( assertTrue(
"Lock NoWait blocked for " + differenceInMillisecs + " ms, this is definitely to much for Nowait", "Lock NoWait blocked for " + differenceInMillis + " ms, this is definitely to much for Nowait",
differenceInMillisecs < 2000 differenceInMillis < 2000
); );
s2.getTransaction().rollback(); s2.getTransaction().rollback();
@ -360,10 +340,40 @@ public class SQLServerDialectTest extends BaseCoreFunctionalTestCase {
s.getTransaction().commit(); s.getTransaction().commit();
} }
@Test
@TestForIssue(jiraKey = "HHH-10879")
public void testKeyReservedKeyword() {
doInHibernate( this::sessionFactory, session -> {
final KeyHolder keyHolder = new KeyHolder();
keyHolder.key = 4000;
session.persist( keyHolder );
} );
}
@Override @Override
protected java.lang.Class<?>[] getAnnotatedClasses() { protected java.lang.Class<?>[] getAnnotatedClasses() {
return new java.lang.Class[] { return new java.lang.Class[] {
Product2.class, Category.class, Folder.class, Contact.class Product2.class, Category.class, Folder.class, Contact.class, KeyHolder.class
}; };
} }
@Entity(name = "KeyHolder")
public static class KeyHolder {
@Id
public Integer key;
}
@Override
protected boolean rebuildSessionFactoryOnError() {
return false;
}
@Override
protected boolean isCleanupTestDataRequired() {
//SQL Server Driver does not deallocate connections right away
sleep(100);
return true;
}
} }

View File

@ -62,4 +62,13 @@ public abstract class BaseUnitTestCase {
} }
} }
} }
protected void sleep(long millis) {
try {
Thread.sleep( millis );
}
catch ( InterruptedException e ) {
Thread.interrupted();
}
}
} }