Skip to content

Commit 1def5d0

Browse files
committed
Merge remote-tracking branch 'upstream/main' into main-perf
2 parents 1e8e38d + a4e2fe5 commit 1def5d0

File tree

114 files changed

+3188
-1109
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+3188
-1109
lines changed

Jenkinsfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ stage('Configure') {
4444
additionalOptions: '-DdbHost=localhost:4000',
4545
notificationRecipients: '[email protected]' ),
4646
new BuildEnvironment( testJdkVersion: '17' ),
47-
new BuildEnvironment( testJdkVersion: '18' ),
48-
// We want to enable preview features when testing early-access builds of OpenJDK:
47+
// We want to enable preview features when testing newer builds of OpenJDK:
4948
// even if we don't use these features, just enabling them can cause side effects
5049
// and it's useful to test that.
5150
new BuildEnvironment( testJdkVersion: '19', testJdkLauncherArgs: '--enable-preview' ),
52-
new BuildEnvironment( testJdkVersion: '20', testJdkLauncherArgs: '--enable-preview' )
51+
new BuildEnvironment( testJdkVersion: '20', testJdkLauncherArgs: '--enable-preview' ),
52+
new BuildEnvironment( testJdkVersion: '21', testJdkLauncherArgs: '--enable-preview' )
5353
];
5454

5555
if ( env.CHANGE_ID ) {

hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/MySQLLegacySqlAstTranslator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ protected String getFromDual() {
240240

241241
@Override
242242
protected String getFromDualForSelectOnly() {
243-
return getDialect().getVersion().isBefore( 5, 7 ) ? getFromDual() : "";
243+
return getDialect().getVersion().isSameOrAfter( 8 ) ? "" : getFromDual();
244244
}
245245

246246
@Override

hibernate-core/src/main/java/org/hibernate/annotations/NamedNativeQuery.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,14 @@
156156
boolean readOnly() default false;
157157

158158
/**
159-
* The query spaces involved in this query.
159+
* The {@linkplain org.hibernate.query.SynchronizeableQuery query spaces}
160+
* involved in this query.
161+
* <p>
162+
* Typically, the names of tables which are referenced by the query.
160163
*
161-
* @see org.hibernate.query.SynchronizeableQuery
164+
* @see org.hibernate.query.SynchronizeableQuery#addSynchronizedQuerySpace
162165
* @see org.hibernate.jpa.HibernateHints#HINT_NATIVE_SPACES
166+
* @see Synchronize
163167
*/
164168
String[] querySpaces() default {};
165169

hibernate-core/src/main/java/org/hibernate/annotations/NamedQuery.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
*
8787
* @see org.hibernate.query.CommonQueryContract#setTimeout(int)
8888
* @see org.hibernate.jpa.HibernateHints#HINT_TIMEOUT
89-
* @see import org.hibernate.jpa.SpecHints#HINT_SPEC_QUERY_TIMEOUT
89+
* @see org.hibernate.jpa.SpecHints#HINT_SPEC_QUERY_TIMEOUT
9090
*/
9191
int timeout() default -1;
9292

hibernate-core/src/main/java/org/hibernate/annotations/Synchronize.java

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,47 @@
1313
import static java.lang.annotation.RetentionPolicy.RUNTIME;
1414

1515
/**
16-
* Specifies the tables that hold state mapped by the annotated derived
17-
* entity, ensuring that auto-flush happens correctly and that queries
18-
* against the derived entity do not return stale data.
16+
* Specifies the tables that hold state mapped by the annotated entity.
1917
* <p>
20-
* This annotation may be used in combination with {@link Subselect}, or
21-
* when an entity maps a database view.
22-
*
18+
* If Hibernate is not aware that a certain table holds state mapped
19+
* by an entity class, then {@linkplain org.hibernate.FlushMode#AUTO
20+
* auto-flush} might not occur when it should, and queries against the
21+
* entity might return stale data.
22+
* <p>
23+
* This annotation might be necessary if:
24+
* <ul>
25+
* <li>the entity maps a database view,
26+
* <li>the entity is persisted using handwritten SQL, that is, using
27+
* {@link SQLSelect @SQLSelect} and friends, or
28+
* <li>the entity is mapped using {@link Subselect @Subselect}.
29+
* </ul>
30+
* <p>
31+
* By default, the table names specified by this annotation are interpreted
32+
* as {@linkplain org.hibernate.boot.model.naming.PhysicalNamingStrategy
33+
* logical names}, and are processed by
34+
* {@link org.hibernate.boot.model.naming.PhysicalNamingStrategy#toPhysicalTableName}.
35+
* But if {@link #logical logical=false}, the table names will be treated
36+
* as physical names, and will not be processed by the naming strategy.
37+
*
2338
* @author Sharath Reddy
39+
*
40+
* @see org.hibernate.query.SynchronizeableQuery
2441
*/
2542
@Target(TYPE)
2643
@Retention(RUNTIME)
2744
public @interface Synchronize {
2845
/**
29-
* Names of tables that hold state mapped by the derived entity.
46+
* Names of tables that hold state mapped by the annotated entity.
3047
* Updates to these tables must be flushed to the database before
31-
* the derived entity is queried.
48+
* execution of any query which refers to the annotated entity.
3249
*/
3350
String[] value();
51+
52+
/**
53+
* Specifies whether the table names given by {@link #value}
54+
* should be interpreted as logical or physical names.
55+
*
56+
* @return {@code true} if they are logical names
57+
*/
58+
boolean logical() default true;
3459
}

hibernate-core/src/main/java/org/hibernate/boot/internal/MetadataBuilderImpl.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,20 +144,19 @@ public MetadataBuilderImpl(MetadataSources sources, StandardServiceRegistry serv
144144
// these should be set during the StandardServiceRegistryBuilder.configure call
145145
applyCfgXmlValues( serviceRegistry.getService( CfgXmlAccessService.class ) );
146146

147-
final ClassLoaderService classLoaderService = serviceRegistry.getService( ClassLoaderService.class );
148-
for ( MetadataBuilderInitializer contributor : classLoaderService.loadJavaServices( MetadataBuilderInitializer.class ) ) {
147+
for ( MetadataBuilderInitializer contributor :
148+
serviceRegistry.getService( ClassLoaderService.class )
149+
.loadJavaServices( MetadataBuilderInitializer.class ) ) {
149150
contributor.contribute( this, serviceRegistry );
150151
}
151152
}
152153

153154
private void applyCfgXmlValues(CfgXmlAccessService service) {
154155
final LoadedConfig aggregatedConfig = service.getAggregatedConfig();
155-
if ( aggregatedConfig == null ) {
156-
return;
157-
}
158-
159-
for ( CacheRegionDefinition cacheRegionDefinition : aggregatedConfig.getCacheRegionDefinitions() ) {
160-
applyCacheRegionDefinition( cacheRegionDefinition );
156+
if ( aggregatedConfig != null ) {
157+
for ( CacheRegionDefinition cacheRegionDefinition : aggregatedConfig.getCacheRegionDefinitions() ) {
158+
applyCacheRegionDefinition( cacheRegionDefinition );
159+
}
161160
}
162161
}
163162

hibernate-core/src/main/java/org/hibernate/boot/internal/MetadataBuildingContextRootImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import org.hibernate.boot.spi.MetadataBuildingOptions;
1616

1717
/**
18-
* Root MetadataBuildingContext
18+
* Root {@link MetadataBuildingContext}.
1919
*/
2020
public class MetadataBuildingContextRootImpl implements MetadataBuildingContext {
2121
private final String contributor;

hibernate-core/src/main/java/org/hibernate/boot/model/FunctionContributions.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77
package org.hibernate.boot.model;
88

9+
import org.hibernate.dialect.Dialect;
910
import org.hibernate.query.sqm.function.SqmFunctionRegistry;
1011
import org.hibernate.service.Service;
1112
import org.hibernate.service.ServiceRegistry;
@@ -28,12 +29,19 @@ public interface FunctionContributions {
2829
SqmFunctionRegistry getFunctionRegistry();
2930

3031
/**
31-
* Access to type information
32+
* Access to type information.
3233
*/
3334
TypeConfiguration getTypeConfiguration();
3435

3536
/**
36-
* Access to {@linkplain Service services}
37+
* Access to {@linkplain Service services}.
3738
*/
3839
ServiceRegistry getServiceRegistry();
40+
41+
/**
42+
* The {@linkplain Dialect SQL Dialect}.
43+
*/
44+
default Dialect getDialect() {
45+
return getTypeConfiguration().getCurrentBaseSqlTypeIndicators().getDialect();
46+
}
3947
}

hibernate-core/src/main/java/org/hibernate/boot/model/TypeContributor.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
* {@link org.hibernate.cfg.Configuration#registerTypeContributor(TypeContributor)}
2222
* or even {@link org.hibernate.boot.MetadataBuilder#applyTypes(TypeContributor)}.
2323
* <li>
24+
* When bootstrapping Hibernate via JPA or {@link org.hibernate.cfg.Configuration},
25+
*
2426
* Finally, in the JPA boostrap process, {@code TypeContributor}s may be
2527
* listed via {@link org.hibernate.jpa.boot.spi.JpaSettings#TYPE_CONTRIBUTORS}.
2628
* </ul>

hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotatedJoinColumn.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,13 +404,14 @@ static AnnotatedJoinColumn buildImplicitJoinTableJoinColumn(
404404
PropertyData inferredData) {
405405
final AnnotatedJoinColumn column = new AnnotatedJoinColumn();
406406
column.setImplicit( true );
407-
column.setNullable( false ); //I break the spec, but it's for good
407+
408408
// column.setPropertyHolder( propertyHolder );
409409
// column.setPropertyName( getRelativePath( propertyHolder, propertyName ) );
410410
// column.setJoins( secondaryTables );
411411
// column.setContext( context );
412412
column.setParent( parent );
413413
column.bind();
414+
column.setNullable( false ); //I break the spec, but it's for good
414415
return column;
415416
}
416417

@@ -425,11 +426,11 @@ static AnnotatedJoinColumn buildExplicitJoinTableJoinColumn(
425426
// column.setPropertyName( getRelativePath( propertyHolder, propertyName ) );
426427
// column.setJoins( secondaryTables );
427428
// column.setContext( context );
428-
column.setNullable( false ); //I break the spec, but it's for good
429429
//done after the annotation to override it
430430
column.setParent( parent );
431431
column.applyJoinAnnotation( joinColumn, inferredData.getPropertyName() );
432432
column.bind();
433+
column.setNullable( false ); //I break the spec, but it's for good
433434
return column;
434435
}
435436

hibernate-core/src/main/java/org/hibernate/boot/model/internal/BinderHelper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ public static boolean isPrimitive(String elementTypeName) {
125125
* property of an {@code @Embeddable}, then every column of that
126126
* embeddable must occur in the list of referenced columns, and the
127127
* order of the columns must line up! Some of these limitations
128-
* could be relaxed using by writing a better algorithm for building
129-
* the synthetic {@link Component}.
128+
* could be relaxed by writing a better algorithm for building the
129+
* synthetic {@link Component}.
130130
*/
131131
public static void createSyntheticPropertyReference(
132132
AnnotatedJoinColumns joinColumns,

hibernate-core/src/main/java/org/hibernate/boot/model/internal/EntityBinder.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,17 +1336,23 @@ private String getDefaultFilterCondition(String filterName) {
13361336
private void bindSynchronize() {
13371337
if ( annotatedClass.isAnnotationPresent( Synchronize.class ) ) {
13381338
final JdbcEnvironment jdbcEnvironment = context.getMetadataCollector().getDatabase().getJdbcEnvironment();
1339-
for ( String table : annotatedClass.getAnnotation(Synchronize.class).value() ) {
1340-
persistentClass.addSynchronizedTable(
1341-
context.getBuildingOptions().getPhysicalNamingStrategy().toPhysicalTableName(
1342-
jdbcEnvironment.getIdentifierHelper().toIdentifier( table ),
1343-
jdbcEnvironment
1344-
).render( jdbcEnvironment.getDialect() )
1345-
);
1339+
final Synchronize synchronize = annotatedClass.getAnnotation(Synchronize.class);
1340+
for ( String table : synchronize.value() ) {
1341+
String physicalName = synchronize.logical() ? toPhysicalName( jdbcEnvironment, table ) : table;
1342+
persistentClass.addSynchronizedTable( physicalName );
13461343
}
13471344
}
13481345
}
13491346

1347+
private String toPhysicalName(JdbcEnvironment jdbcEnvironment, String logicalName) {
1348+
return context.getBuildingOptions().getPhysicalNamingStrategy()
1349+
.toPhysicalTableName(
1350+
jdbcEnvironment.getIdentifierHelper().toIdentifier( logicalName ),
1351+
jdbcEnvironment
1352+
)
1353+
.render( jdbcEnvironment.getDialect() );
1354+
}
1355+
13501356
@SuppressWarnings({"rawtypes", "unchecked"})
13511357
private void bindCustomPersister() {
13521358
//set persister if needed

0 commit comments

Comments
 (0)