Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
26bcbb2
HHH-18323 Add test for issue
dreab8 Oct 7, 2024
672922b
Fix some unused imports causing spotless check failures
mbellade Nov 26, 2024
7632220
HHH-18861 - Improve GitHub release announcement body for automated re…
sebersole Nov 26, 2024
26bbaac
HHH-12866 test showing problem is fixed
gavinking Nov 26, 2024
a93e8e6
HHH-18881 Modified test case from Jira issue
cigaly Nov 26, 2024
8b517c5
HHH-18881 Implement fromEncodedString as inverse of appendEncodedString
cigaly Nov 26, 2024
cd47e91
HHH-18610 Add test for issue
dreab8 Oct 1, 2024
49886d1
HHH-18610 SQLGrammarException: Unable to find column position by name…
dreab8 Oct 1, 2024
1fe23ae
HHH-18854 - Changes for Hibernate Reactive 3.0 integration
DavideD Nov 15, 2024
f9d2e8e
HHH-18883 fix for TransientObjectException
gavinking Nov 27, 2024
61d0a81
two minor changes
gavinking Nov 27, 2024
76b3105
HHH-18875 Avoid need for refletive registrations triggered by Standar…
Sanne Nov 22, 2024
3d0545e
HHH-18875 Avoid using the deprecated constructors of StandardStack
Sanne Nov 22, 2024
39f5946
HHH-18875 Remove the related GraalVM reflective registrations
Sanne Nov 22, 2024
1287d93
HHH-15102 allow -- style comments in native SQL query
gavinking Nov 27, 2024
107e426
HHH-18872 Test reproducing the issue
gtoison Nov 22, 2024
3cfa7c7
HHH-18872 Rename and cleanup test
mbellade Nov 22, 2024
d723ff0
HHH-18872 Resolve concrete entity name when initializing lazy to-ones
mbellade Nov 22, 2024
7ca9d0a
HHH-18069 - Add test
jrenaat May 27, 2024
9ed1119
HHH-18069 - Add test
dreab8 Nov 27, 2024
b6ee791
HHH-18069 NullPointerException when unioning partition results
dreab8 Nov 27, 2024
79aa178
HHH-16516 rework CamelCaseToUnderscoresNamingStrategy and handle quot…
gavinking Nov 28, 2024
d60aa27
HHH-18810 expose impliedJavaType of BasicValue
gavinking Nov 28, 2024
78cd996
fix @DialectOverrides.SQLRestrictions
gavinking Nov 28, 2024
e0c95b7
HHH-13932 add test showing issue fixed
gavinking Nov 29, 2024
2fa1765
HHH-18709 Add test for issue
mbellade Oct 29, 2024
d433133
HHH-18709 Use path to infer criteria value-bind parameter type on `set`
mbellade Nov 28, 2024
38fb68a
correctly describe automatic quoting in doc
gavinking Nov 29, 2024
817f629
minor code cleanups to Identifier
gavinking Nov 29, 2024
297db57
refactorings to EntityType, minor code cleanups to ManyToOneType
gavinking Nov 29, 2024
58aaa79
HHH-16054 add test showing issue fixed
gavinking Nov 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions ci/release/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,10 @@ pipeline {
env.RELEASE_VERSION = releaseVersion.toString()
env.DEVELOPMENT_VERSION = developmentVersion.toString()

// def matchingFiles = findFiles(glob: "/release_notes.md")
// env.SCRIPT_OPTIONS = " --notes=${matchingFiles[0]}"
def notesFile = new File( "release_notes.md" )
assert notesFile.exists
env.SCRIPT_OPTIONS = " --notes=${notesFile.absolutePath}"

if ( params.RELEASE_DRY_RUN ) {
env.SCRIPT_OPTIONS += " -d"
}
Expand Down
3 changes: 2 additions & 1 deletion documentation/src/main/asciidoc/introduction/Advanced.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -582,9 +582,10 @@ We happen to not much like the naming rules defined by JPA, which specify that m
We bet you could easily come up with a much better `ImplicitNamingStrategy` than that!
(Hint: it should always produce legit mixed case identifiers.)
====

[TIP]
====
A popular `PhysicalNamingStrategy` produces snake case identifiers.
The popular link:{doc-javadoc-url}org/hibernate/boot/model/naming/PhysicalNamingStrategySnakeCaseImpl.html[`PhysicalNamingStrategySnakeCaseImpl`] produces snake case identifiers.
====

Custom naming strategies may be enabled using the configuration properties we already mentioned without much explanation back in <<minimizing>>.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -503,10 +503,11 @@ We'll have more to say about them in <<naming-strategies>>.
[[quoted-identifiers]]
=== Quoting SQL identifiers

By default, Hibernate never quotes SQL table and column names in generated SQL.
By default, Hibernate never quotes a SQL table or column name in generated SQL when the name contains only alphanumeric characters.
This behavior is usually much more convenient, especially when working with a legacy schema, since unquoted identifiers aren't case-sensitive, and so Hibernate doesn't need to know or care whether a column is named `NAME`, `name`, or `Name` on the database side.
On the other hand, any table or column name containing a punctuation character like `$` is automatically quoted by default.

The following settings enable automatic quoting:
The following settings enable additional automatic quoting:

.Settings for identifier quoting
[%breakable,cols="35,~"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public interface DialectOverride {

org.hibernate.annotations.SQLRestriction override();
}
@Target({METHOD, FIELD})
@Target({METHOD, FIELD, TYPE})
@Retention(RUNTIME)
@interface SQLRestrictions {
SQLRestriction[] value();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.hibernate.boot.models.annotations.internal.JoinColumnJpaAnnotation;
import org.hibernate.boot.spi.MetadataBuildingContext;
import org.hibernate.boot.spi.PropertyData;
import org.hibernate.internal.util.collections.CollectionHelper;
import org.hibernate.models.spi.MemberDetails;
import org.hibernate.models.spi.SourceModelBuildingContext;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import java.util.Properties;

import org.hibernate.boot.BootLogging;
import org.hibernate.internal.util.collections.CollectionHelper;
import org.hibernate.resource.beans.spi.ManagedBean;
import org.hibernate.usertype.ParameterizedType;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import org.hibernate.boot.models.annotations.spi.DialectOverrider;
import org.hibernate.boot.spi.MetadataBuildingContext;
import org.hibernate.dialect.Dialect;
import org.hibernate.internal.util.collections.CollectionHelper;
import org.hibernate.models.spi.AnnotationTarget;
import org.hibernate.models.spi.SourceModelBuildingContext;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.hibernate.boot.spi.MetadataBuildingContext;
import org.hibernate.engine.spi.FilterDefinition;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.collections.CollectionHelper;
import org.hibernate.metamodel.mapping.JdbcMapping;
import org.hibernate.models.spi.AnnotationTarget;
import org.hibernate.models.spi.SourceModelBuildingContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*/
package org.hibernate.boot.model.internal;

import java.util.Collections;
import java.util.Map;

import org.hibernate.AnnotationException;
Expand All @@ -15,7 +14,6 @@
import org.hibernate.MappingException;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.internal.util.LockModeConverter;
import org.hibernate.internal.util.collections.CollectionHelper;
import org.hibernate.internal.util.config.ConfigurationHelper;
import org.hibernate.jpa.HibernateHints;
import org.hibernate.jpa.LegacySpecHints;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,88 +4,9 @@
*/
package org.hibernate.boot.model.naming;

import java.util.Locale;

import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;

/**
* Originally copied from Spring Boot as this strategy is popular there
* (original name is SpringPhysicalNamingStrategy).
*
* @author Phillip Webb
* @author Madhura Bhave
* @deprecated Use {@link PhysicalNamingStrategySnakeCaseImpl}.
*/
public class CamelCaseToUnderscoresNamingStrategy implements PhysicalNamingStrategy {

@Override
public Identifier toPhysicalCatalogName(Identifier logicalName, JdbcEnvironment jdbcEnvironment) {
return apply( logicalName, jdbcEnvironment );
}

@Override
public Identifier toPhysicalSchemaName(Identifier logicalName, JdbcEnvironment jdbcEnvironment) {
return apply( logicalName, jdbcEnvironment );
}

@Override
public Identifier toPhysicalTableName(Identifier logicalName, JdbcEnvironment jdbcEnvironment) {
return apply( logicalName, jdbcEnvironment );
}

@Override
public Identifier toPhysicalSequenceName(Identifier logicalName, JdbcEnvironment jdbcEnvironment) {
return apply( logicalName, jdbcEnvironment );
}

@Override
public Identifier toPhysicalColumnName(Identifier logicalName, JdbcEnvironment jdbcEnvironment) {
return apply( logicalName, jdbcEnvironment );
}

private Identifier apply(final Identifier name, final JdbcEnvironment jdbcEnvironment) {
if ( name == null ) {
return null;
}
StringBuilder builder = new StringBuilder( name.getText().replace( '.', '_' ) );
for ( int i = 1; i < builder.length() - 1; i++ ) {
if ( isUnderscoreRequired( builder.charAt( i - 1 ), builder.charAt( i ), builder.charAt( i + 1 ) ) ) {
builder.insert( i++, '_' );
}
}
return getIdentifier( builder.toString(), name.isQuoted(), jdbcEnvironment );
}

/**
* Get an identifier for the specified details. By default this method will return an identifier
* with the name adapted based on the result of {@link #isCaseInsensitive(JdbcEnvironment)}
*
* @param name the name of the identifier
* @param quoted if the identifier is quoted
* @param jdbcEnvironment the JDBC environment
*
* @return an identifier instance
*/
protected Identifier getIdentifier(String name, final boolean quoted, final JdbcEnvironment jdbcEnvironment) {
if ( isCaseInsensitive( jdbcEnvironment ) ) {
name = name.toLowerCase( Locale.ROOT );
}
return new Identifier( name, quoted );
}

/**
* Specify whether the database is case sensitive.
*
* @param jdbcEnvironment the JDBC environment which can be used to determine case
*
* @return true if the database is case insensitive sensitivity
*/
protected boolean isCaseInsensitive(JdbcEnvironment jdbcEnvironment) {
return true;
}

private boolean isUnderscoreRequired(final char before, final char current, final char after) {
return ( Character.isLowerCase( before ) || Character.isDigit( before ) ) && Character.isUpperCase( current ) && ( Character.isLowerCase(
after ) || Character.isDigit( after ) );
}

@Deprecated(since = "7", forRemoval = true)
public class CamelCaseToUnderscoresNamingStrategy extends PhysicalNamingStrategySnakeCaseImpl {
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
package org.hibernate.boot.model.naming;

import org.hibernate.internal.util.StringHelper;
import static org.hibernate.internal.util.StringHelper.isEmpty;

/**
* Models an identifier (name), retrieved from the database.
Expand All @@ -24,13 +24,13 @@ protected DatabaseIdentifier(String text) {
}

public static DatabaseIdentifier toIdentifier(String text) {
if ( StringHelper.isEmpty( text ) ) {
if ( isEmpty( text ) ) {
return null;
}
else if ( isQuoted( text ) ) {
// exclude the quotes from text
final String unquotedtext = text.substring( 1, text.length() - 1 );
return new DatabaseIdentifier( unquotedtext );
final String unquoted = text.substring( 1, text.length() - 1 );
return new DatabaseIdentifier( unquoted );
}
else {
return new DatabaseIdentifier( text );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
import java.util.Locale;

import org.hibernate.dialect.Dialect;
import org.hibernate.internal.util.StringHelper;

import static java.lang.Character.isLetter;
import static java.lang.Character.isLetterOrDigit;
import static java.lang.Character.isWhitespace;
import static org.hibernate.internal.util.StringHelper.isBlank;
import static org.hibernate.internal.util.StringHelper.isEmpty;

/**
* Models an identifier (name), which may or may not be quoted.
Expand Down Expand Up @@ -83,13 +86,13 @@ public static Identifier toIdentifier(String text, boolean quote, boolean quoteO
int start = 0;
int end = text.length();
while ( start < end ) {
if ( !Character.isWhitespace( text.charAt( start ) ) ) {
if ( !isWhitespace( text.charAt( start ) ) ) {
break;
}
start++;
}
while ( start < end ) {
if ( !Character.isWhitespace( text.charAt( end - 1 ) ) ) {
if ( !isWhitespace( text.charAt( end - 1 ) ) ) {
break;
}
end--;
Expand All @@ -102,14 +105,14 @@ public static Identifier toIdentifier(String text, boolean quote, boolean quoteO
else if ( quoteOnNonIdentifierChar && !quote ) {
// Check the letters to determine if we must quote the text
char c = text.charAt( start );
if ( !Character.isLetter( c ) && c != '_' ) {
if ( !isLetter( c ) && c != '_' ) {
// SQL identifiers must begin with a letter or underscore
quote = true;
}
else {
for ( int i = start + 1; i < end; i++ ) {
c = text.charAt( i );
if ( !Character.isLetterOrDigit( c ) && c != '_' ) {
if ( !isLetterOrDigit( c ) && c != '_' ) {
quote = true;
break;
}
Expand Down Expand Up @@ -163,7 +166,7 @@ public static String unQuote(String name) {
* @param quoted Is this a quoted identifier?
*/
public Identifier(String text, boolean quoted) {
if ( StringHelper.isEmpty( text ) ) {
if ( isEmpty( text ) ) {
throw new IllegalIdentifierException( "Identifier text cannot be null" );
}
if ( isQuoted( text ) ) {
Expand Down Expand Up @@ -234,11 +237,9 @@ public String toString() {

@Override
public boolean equals(Object o) {
if ( !(o instanceof Identifier) ) {
if ( !(o instanceof Identifier that) ) {
return false;
}

final Identifier that = (Identifier) o;
return getCanonicalName().equals( that.getCanonicalName() );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public Identifier determinePrimaryTableName(ImplicitEntityNameSource source) {
throw new HibernateException( "Entity naming information was not provided." );
}

String tableName = transformEntityName( source.getEntityNaming() );
final String tableName = transformEntityName( source.getEntityNaming() );

if ( tableName == null ) {
// todo : add info to error message - but how to know what to write since we failed to interpret the naming source
Expand Down Expand Up @@ -136,9 +136,9 @@ public Identifier determineJoinColumnName(ImplicitJoinColumnNameSource source) {

// todo : we need to better account for "referencing relationship property"

final String name;
final String referencedColumnName = source.getReferencedColumnName().getText();

String referencedColumnName = source.getReferencedColumnName().getText();
final String name;
if ( source.getNature() == ELEMENT_COLLECTION
|| source.getAttributePath() == null ) {
name = transformEntityName( source.getEntityNaming() )
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* SPDX-License-Identifier: LGPL-2.1-or-later
* Copyright Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.boot.model.naming;

import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;

import java.util.Locale;

import static java.lang.Character.isDigit;
import static java.lang.Character.isLowerCase;
import static java.lang.Character.isUpperCase;

/**
* Converts {@code camelCase} or {@code MixedCase} logical names to {@code snake_case}.
*
* @author Phillip Webb
* @author Madhura Bhave
*/
// Originally copied from Spring's SpringPhysicalNamingStrategy as this strategy is popular there.
public class PhysicalNamingStrategySnakeCaseImpl implements PhysicalNamingStrategy {

@Override
public Identifier toPhysicalCatalogName(Identifier logicalName, JdbcEnvironment jdbcEnvironment) {
return apply( logicalName );
}

@Override
public Identifier toPhysicalSchemaName(Identifier logicalName, JdbcEnvironment jdbcEnvironment) {
return apply( logicalName );
}

@Override
public Identifier toPhysicalTableName(Identifier logicalName, JdbcEnvironment jdbcEnvironment) {
return apply( logicalName );
}

@Override
public Identifier toPhysicalSequenceName(Identifier logicalName, JdbcEnvironment jdbcEnvironment) {
return apply( logicalName );
}

@Override
public Identifier toPhysicalColumnName(Identifier logicalName, JdbcEnvironment jdbcEnvironment) {
return apply( logicalName );
}

private Identifier apply(final Identifier name) {
if ( name == null ) {
return null;
}
else if ( name.isQuoted() ) {
return quotedIdentifier( name );
}
else {
return unquotedIdentifier( name );
}
}

private String camelCaseToSnakeCase(String name) {
final StringBuilder builder = new StringBuilder( name.replace( '.', '_' ) );
for ( int i = 1; i < builder.length() - 1; i++ ) {
if ( isUnderscoreRequired( builder.charAt( i - 1 ), builder.charAt( i ), builder.charAt( i + 1 ) ) ) {
builder.insert( i++, '_' );
}
}
return builder.toString();
}

protected Identifier unquotedIdentifier(Identifier name) {
return new Identifier( camelCaseToSnakeCase( name.getText() ).toLowerCase( Locale.ROOT ) );
}

protected Identifier quotedIdentifier(Identifier quotedName) {
return quotedName;
}

private boolean isUnderscoreRequired(final char before, final char current, final char after) {
return ( isLowerCase( before ) || isDigit( before ) )
&& isUpperCase( current )
&& ( isLowerCase( after ) || isDigit( after ) );
}
}
Loading
Loading