Skip to content

Commit acd4e0e

Browse files
committed
Fix HANA test, skip one SQL Server test due to precision issues and get rid of old cruft in AbstractEntityPersister
1 parent 92d447c commit acd4e0e

File tree

5 files changed

+25
-185
lines changed

5 files changed

+25
-185
lines changed

hibernate-core/src/main/java/org/hibernate/dialect/HANASqlAstTranslator.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77
package org.hibernate.dialect;
88

9+
import org.hibernate.MappingException;
910
import org.hibernate.engine.spi.SessionFactoryImplementor;
1011
import org.hibernate.query.sqm.BinaryArithmeticOperator;
1112
import org.hibernate.query.sqm.ComparisonOperator;
@@ -23,6 +24,7 @@
2324
import org.hibernate.sql.ast.tree.select.QueryPart;
2425
import org.hibernate.sql.ast.tree.select.QuerySpec;
2526
import org.hibernate.sql.exec.spi.JdbcOperation;
27+
import org.hibernate.sql.model.internal.TableInsertStandard;
2628

2729
/**
2830
* A SQL AST translator for HANA.
@@ -144,4 +146,15 @@ protected String getFromDual() {
144146
protected String getFromDualForSelectOnly() {
145147
return getFromDual();
146148
}
149+
150+
@Override
151+
protected void renderInsertIntoNoColumns(TableInsertStandard tableInsert) {
152+
throw new MappingException(
153+
String.format(
154+
"The INSERT statement for table [%s] contains no column, and this is not supported by [%s]",
155+
tableInsert.getMutatingTable().getTableId(),
156+
getDialect()
157+
)
158+
);
159+
}
147160
}

hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java

Lines changed: 0 additions & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -397,9 +397,6 @@ public abstract class AbstractEntityPersister
397397
private String sqlVersionSelectString;
398398
private Map<String, SingleIdArrayLoadPlan> sqlLazySelectStringsByFetchGroup;
399399

400-
private String[] sqlLazyUpdateStrings;
401-
private String sqlUpdateByRowIdString;
402-
private String sqlLazyUpdateByRowIdString;
403400

404401
private GeneratedValuesProcessor insertGeneratedValuesProcessor;
405402
private GeneratedValuesProcessor updateGeneratedValuesProcessor;
@@ -935,10 +932,6 @@ public DeleteCoordinator getDeleteCoordinator() {
935932
return deleteCoordinator;
936933
}
937934

938-
public String[] getSQLLazyUpdateStrings() {
939-
return sqlLazyUpdateStrings;
940-
}
941-
942935
public String getVersionSelectString() {
943936
return sqlVersionSelectString;
944937
}
@@ -2743,132 +2736,6 @@ protected boolean check(
27432736

27442737
private static final boolean[] SINGLE_TRUE = new boolean[] { true };
27452738

2746-
public String generateUpdateString(boolean[] includeProperty, int j, boolean useRowId) {
2747-
return generateUpdateString( includeProperty, j, null, useRowId );
2748-
}
2749-
2750-
/**
2751-
* Generate the SQL that updates a row by id (and version)
2752-
*/
2753-
public String generateUpdateString(
2754-
final boolean[] includeProperty,
2755-
final int j,
2756-
final Object[] oldFields,
2757-
final boolean useRowId) {
2758-
final Update update = new Update( getFactory().getJdbcServices().getDialect() ).setTableName( getTableName( j ) );
2759-
2760-
boolean hasColumns = false;
2761-
for ( int index = 0; index < attributeMappings.size(); index++ ) {
2762-
final AttributeMapping attributeMapping = attributeMappings.get( index );
2763-
if ( isPropertyOfTable( index, j ) ) {
2764-
// `attributeMapping` is an attribute of the table we are updating
2765-
2766-
if ( ! lobProperties.contains( index ) ) {
2767-
// HHH-4635
2768-
// Oracle expects all Lob properties to be last in inserts
2769-
// and updates. Insert them at the end - see below
2770-
2771-
if ( includeProperty[ index ] ) {
2772-
update.addColumns(
2773-
getPropertyColumnNames( index ),
2774-
propertyColumnUpdateable[index ],
2775-
propertyColumnWriters[index]
2776-
);
2777-
hasColumns = true;
2778-
}
2779-
else {
2780-
final Generator generator = attributeMapping.getGenerator();
2781-
if ( generator!=null
2782-
&& generator.generatesOnUpdate()
2783-
&& generator.generatedByDatabase() ) {
2784-
final InDatabaseGenerator databaseGenerator = (InDatabaseGenerator) generator;
2785-
final Dialect dialect = getFactory().getJdbcServices().getDialect();
2786-
if ( databaseGenerator.referenceColumnsInSql(dialect) ) {
2787-
update.addColumns(
2788-
getPropertyColumnNames(index),
2789-
SINGLE_TRUE,
2790-
databaseGenerator.getReferencedColumnValues(dialect)
2791-
);
2792-
hasColumns = true;
2793-
}
2794-
}
2795-
}
2796-
}
2797-
}
2798-
}
2799-
2800-
// HHH-4635
2801-
// Oracle expects all Lob properties to be last in inserts
2802-
// and updates. Insert them at the end.
2803-
for ( int i : lobProperties ) {
2804-
if ( includeProperty[i] && isPropertyOfTable( i, j ) ) {
2805-
// this property belongs on the table and is to be inserted
2806-
update.addColumns(
2807-
getPropertyColumnNames( i ),
2808-
propertyColumnUpdateable[i], propertyColumnWriters[i]
2809-
);
2810-
hasColumns = true;
2811-
}
2812-
}
2813-
2814-
// select the correct row by either pk or row id
2815-
if ( useRowId ) {
2816-
update.addPrimaryKeyColumns( new String[] {rowIdName} ); //TODO: eventually, rowIdName[j]
2817-
}
2818-
else {
2819-
update.addPrimaryKeyColumns( getKeyColumns( j ) );
2820-
}
2821-
2822-
if ( j == 0 && isVersioned() && entityMetamodel.getOptimisticLockStyle().isVersion() ) {
2823-
// this is the root (versioned) table, and we are using version-based
2824-
// optimistic locking; if we are not updating the version, also don't
2825-
// check it (unless this is a "generated" version column)!
2826-
if ( checkVersion( includeProperty ) ) {
2827-
update.setVersionColumnName( getVersionColumnName() );
2828-
hasColumns = true;
2829-
}
2830-
}
2831-
else if ( isAllOrDirtyOptLocking() && oldFields != null ) {
2832-
// we are using "all" or "dirty" property-based optimistic locking
2833-
2834-
boolean[] includeInWhere = entityMetamodel.getOptimisticLockStyle().isAll()
2835-
//optimistic-lock="all", include all updatable properties
2836-
? getPropertyUpdateability()
2837-
//optimistic-lock="dirty", include all properties we are updating this time
2838-
: includeProperty;
2839-
2840-
boolean[] versionability = getPropertyVersionability();
2841-
Type[] types = getPropertyTypes();
2842-
for ( int i = 0; i < entityMetamodel.getPropertySpan(); i++ ) {
2843-
boolean include = includeInWhere[i] &&
2844-
isPropertyOfTable( i, j ) &&
2845-
versionability[i];
2846-
if ( include ) {
2847-
// this property belongs to the table, and it is not specifically
2848-
// excluded from optimistic locking by optimistic-lock="false"
2849-
String[] propertyColumnNames = getPropertyColumnNames( i );
2850-
String[] propertyColumnWriters = getPropertyColumnWriters( i );
2851-
boolean[] propertyNullness = types[i].toColumnNullness( oldFields[i], getFactory() );
2852-
for ( int k = 0; k < propertyNullness.length; k++ ) {
2853-
if ( propertyNullness[k] ) {
2854-
update.addWhereColumn( propertyColumnNames[k], "=" + propertyColumnWriters[k] );
2855-
}
2856-
else {
2857-
update.addWhereColumn( propertyColumnNames[k], " is null" );
2858-
}
2859-
}
2860-
}
2861-
}
2862-
2863-
}
2864-
2865-
if ( getFactory().getSessionFactoryOptions().isCommentsEnabled() ) {
2866-
update.setComment( "update " + getEntityName() );
2867-
}
2868-
2869-
return hasColumns ? update.toStatementString() : null;
2870-
}
2871-
28722739
public final boolean checkVersion(final boolean[] includeProperty) {
28732740
return includeProperty[getVersionProperty()] || entityMetamodel.isVersionGeneratedByDatabase();
28742741
}
@@ -3095,13 +2962,6 @@ protected void logStaticSQL() {
30952962
LOG.debugf( " Delete (%s): %s", tablePosition, ( (JdbcOperation) mutation ).getSqlString() );
30962963
}
30972964
} );
3098-
3099-
if ( sqlUpdateByRowIdString != null ) {
3100-
LOG.debugf( " Update by row id (all fields): %s", sqlUpdateByRowIdString );
3101-
}
3102-
if ( sqlLazyUpdateByRowIdString != null ) {
3103-
LOG.debugf( " Update by row id (non-lazy fields): %s", sqlLazyUpdateByRowIdString );
3104-
}
31052965
}
31062966
}
31072967

@@ -3220,20 +3080,6 @@ private void doLateInit() {
32203080
deleteCoordinator = buildDeleteCoordinator();
32213081

32223082
final int joinSpan = getTableSpan();
3223-
sqlLazyUpdateStrings = new String[joinSpan];
3224-
3225-
sqlUpdateByRowIdString = rowIdName == null ?
3226-
null :
3227-
generateUpdateString( getPropertyUpdateability(), 0, true );
3228-
sqlLazyUpdateByRowIdString = rowIdName == null ?
3229-
null :
3230-
generateUpdateString( getNonLazyPropertyUpdateability(), 0, true );
3231-
3232-
for ( int j = 0; j < joinSpan; j++ ) {
3233-
sqlLazyUpdateStrings[j] = customSQLUpdate[j] == null
3234-
? generateUpdateString( getNonLazyPropertyUpdateability(), j, false )
3235-
: substituteBrackets( customSQLUpdate[j] );
3236-
}
32373083

32383084
tableHasColumns = new boolean[joinSpan];
32393085
for ( int j = 0; j < joinSpan; j++ ) {

hibernate-core/src/test/java/org/hibernate/orm/test/boot/database/qualfiedTableNaming/DefaultCatalogAndSchemaTest.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -415,9 +415,6 @@ private void verifyEntityPersisterQualifiers(Class<?> entityClass, ExpectedQuali
415415
} );
416416
verifyOnlyQualifier( sqlUpdateStrings, SqlType.RUNTIME, jpaEntityName, expectedQualifier );
417417

418-
verifyOnlyQualifier( persister.getSQLLazyUpdateStrings(), SqlType.RUNTIME,
419-
jpaEntityName, expectedQualifier );
420-
421418
final MutationOperationGroup staticDeleteGroup = persister.getDeleteCoordinator().getStaticDeleteGroup();
422419
final String[] sqlDeleteStrings = new String[staticDeleteGroup.getNumberOfOperations()];
423420
staticDeleteGroup.forEachOperation( (tablePosition, operation) -> {

hibernate-core/src/test/java/org/hibernate/orm/test/dialect/HANADialectTestCase.java

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,29 @@
1111

1212
import org.hibernate.LockMode;
1313
import org.hibernate.LockOptions;
14+
import org.hibernate.MappingException;
1415
import org.hibernate.boot.MetadataSources;
1516
import org.hibernate.boot.registry.StandardServiceRegistry;
1617
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
1718
import org.hibernate.cfg.AvailableSettings;
1819
import org.hibernate.dialect.HANAColumnStoreDialect;
19-
import org.hibernate.engine.jdbc.mutation.MutationExecutor;
20-
import org.hibernate.engine.jdbc.mutation.group.PreparedStatementDetails;
21-
import org.hibernate.engine.jdbc.mutation.spi.MutationExecutorService;
2220
import org.hibernate.engine.spi.SessionFactoryImplementor;
23-
import org.hibernate.id.PostInsertIdentityPersister;
24-
import org.hibernate.persister.entity.SingleTableEntityPersister;
25-
import org.hibernate.sql.model.MutationOperationGroup;
2621

2722
import org.hibernate.testing.TestForIssue;
2823
import org.hibernate.testing.junit4.BaseUnitTestCase;
2924
import org.hibernate.testing.orm.junit.ServiceRegistryScope;
30-
import org.hibernate.testing.transaction.TransactionUtil2;
3125
import org.junit.Test;
3226

3327
import jakarta.persistence.Entity;
3428
import jakarta.persistence.GeneratedValue;
3529
import jakarta.persistence.GenerationType;
3630
import jakarta.persistence.Id;
3731
import jakarta.persistence.Table;
32+
import org.hamcrest.MatcherAssert;
3833

39-
import static org.assertj.core.api.Assertions.assertThat;
34+
import static org.hamcrest.core.Is.is;
4035
import static org.junit.Assert.assertEquals;
36+
import static org.junit.jupiter.api.Assertions.fail;
4137

4238
public class HANADialectTestCase extends BaseUnitTestCase {
4339
@Test
@@ -52,26 +48,12 @@ public void testSqlGeneratedForIdentityInsertNoColumns() {
5248
metadataSources.addAnnotatedClass( EntityWithIdentity.class );
5349

5450
try ( SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor) metadataSources.buildMetadata().buildSessionFactory() ) {
55-
final PostInsertIdentityPersister entityDescriptor = (PostInsertIdentityPersister) sessionFactory.getRuntimeMetamodels()
56-
.getMappingMetamodel()
57-
.getEntityDescriptor( EntityWithIdentity.class );
58-
final MutationOperationGroup staticInsertGroup = ( (SingleTableEntityPersister) entityDescriptor ).getInsertCoordinator().getStaticInsertGroup();
59-
60-
final MutationExecutorService mutationExecutorService = sessionFactory
61-
.getServiceRegistry()
62-
.getService( MutationExecutorService.class );
63-
64-
TransactionUtil2.inTransaction(
65-
sessionFactory,
66-
(session) -> {
67-
final MutationExecutor mutationExecutor = mutationExecutorService.createExecutor(
68-
() -> null,
69-
staticInsertGroup,
70-
session
71-
);
72-
final PreparedStatementDetails statementDetails = mutationExecutor.getPreparedStatementDetails( "EntityWithIdentity" );
73-
assertThat( statementDetails.getSqlString() ).isEqualTo( "insert into EntityWithIdentity values ( )" );
74-
}
51+
fail( "Should have thrown MappingException!" );
52+
}
53+
catch (MappingException e) {
54+
MatcherAssert.assertThat(
55+
e.getMessage(),
56+
is( "The INSERT statement for table [EntityWithIdentity] contains no column, and this is not supported by [" + HANAColumnStoreDialect.class.getName() + "]" )
7557
);
7658
}
7759
}

hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/temporals/MultipleGeneratedValuesTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
import org.hibernate.HibernateError;
1515
import org.hibernate.annotations.CurrentTimestamp;
16+
import org.hibernate.dialect.SQLServerDialect;
1617
import org.hibernate.dialect.SybaseASEDialect;
1718
import org.hibernate.tuple.GenerationTiming;
1819

@@ -35,6 +36,7 @@
3536
@SessionFactory
3637
@RequiresDialectFeature(feature = DialectFeatureChecks.CurrentTimestampHasMicrosecondPrecision.class, comment = "Without this, we might not see an update to the timestamp")
3738
@SkipForDialect( dialectClass = SybaseASEDialect.class, matchSubTypes = true, reason = "CURRENT_TIMESTAMP not supported in insert/update in Sybase ASE. Also see https://groups.google.com/g/comp.databases.sybase/c/j-RxPnF3img" )
39+
@SkipForDialect( dialectClass = SQLServerDialect.class, matchSubTypes = true, reason = "CURRENT_TIMESTAMP has millisecond precision" )
3840
public class MultipleGeneratedValuesTests {
3941
@Test
4042
public void test(SessionFactoryScope scope) {

0 commit comments

Comments
 (0)