Small cleanup and add migration guide sections

This commit is contained in:
Christian Beikov 2021-12-06 17:12:59 +01:00
parent 9028adc30e
commit bab32c3100
4 changed files with 66 additions and 96 deletions

View File

@ -21,7 +21,7 @@ import org.hibernate.type.descriptor.jdbc.JdbcType;
*/
public abstract class AbstractSingleColumnStandardBasicType<T>
extends AbstractStandardBasicType<T>
implements SingleColumnType<T> {
implements Type {
public AbstractSingleColumnStandardBasicType(JdbcType jdbcType, JavaType<T> javaTypeDescriptor) {
super( jdbcType, javaTypeDescriptor );

View File

@ -251,32 +251,6 @@ public abstract class AbstractStandardBasicType<T>
return isDirty( oldHydratedState, currentState );
}
private final Object nullSafeGet(
ResultSet rs,
String[] names,
SharedSessionContractImplementor session,
Object owner) throws SQLException {
return nullSafeGet( rs, names[0], session );
}
private final Object nullSafeGet(ResultSet rs, String name, SharedSessionContractImplementor session, Object owner)
throws SQLException {
return nullSafeGet( rs, name, session );
}
public final T nullSafeGet(ResultSet rs, String name, final SharedSessionContractImplementor session) throws SQLException {
return nullSafeGet( rs, name, (WrapperOptions) session );
}
protected final T nullSafeGet(ResultSet rs, String name, WrapperOptions options) throws SQLException {
// return remapSqlTypeDescriptor( options ).getExtractor( javaTypeDescriptor ).extract( rs, name, options );
throw new UnsupportedOperationException( "Reading JDBC results by name/alias is no longer supported (" + getClass().getTypeName() + ")" );
}
public Object get(ResultSet rs, String name, SharedSessionContractImplementor session) throws HibernateException, SQLException {
return nullSafeGet( rs, name, session );
}
@Override
public final void nullSafeSet(
PreparedStatement st,
@ -291,10 +265,6 @@ public abstract class AbstractStandardBasicType<T>
jdbcType.getBinder( javaTypeDescriptor ).bind( st, value, index, options );
}
public void set(PreparedStatement st, T value, int index, SharedSessionContractImplementor session) throws HibernateException, SQLException {
nullSafeSet( st, value, index, (WrapperOptions) session );
}
@Override
@SuppressWarnings({ "unchecked" })
public final String toLoggableString(Object value, SessionFactoryImplementor factory) {

View File

@ -1,65 +0,0 @@
/*
* 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.type;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
/**
* Provide convenient methods for binding and extracting values for use with {@link BasicType}.
*
* @author Steve Ebersole
*/
public interface SingleColumnType<T> extends Type {
/**
* Get a column value from a result set by name.
*
* @param rs The result set from which to extract the value.
* @param name The name of the value to extract.
* @param session The session from which the request originates
*
* @return The extracted value.
*
* @throws HibernateException Generally some form of mismatch error.
* @throws SQLException Indicates problem making the JDBC call(s).
*/
T nullSafeGet(ResultSet rs, String name, SharedSessionContractImplementor session) throws HibernateException, SQLException;
/**
* Get a column value from a result set, without worrying about the possibility of null values.
*
* @param rs The result set from which to extract the value.
* @param name The name of the value to extract.
* @param session The session from which the request originates
*
* @return The extracted value.
*
* @throws HibernateException Generally some form of mismatch error.
* @throws SQLException Indicates problem making the JDBC call(s).
*/
Object get(ResultSet rs, String name, SharedSessionContractImplementor session) throws HibernateException, SQLException;
/**
* Set a parameter value without worrying about the possibility of null
* values. Called from {@link #nullSafeSet} after nullness checks have
* been performed.
*
* @param st The statement into which to bind the parameter value.
* @param value The parameter value to bind.
* @param index The position or index at which to bind the param value.
* @param session The session from which the request originates
*
* @throws HibernateException Generally some form of mismatch error.
* @throws SQLException Indicates problem making the JDBC call(s).
*/
void set(PreparedStatement st, T value, int index, SharedSessionContractImplementor session) throws HibernateException, SQLException;
}

View File

@ -296,3 +296,68 @@ JOIN Node.node3.node2.node1
as you can see, this leads to a lot of joins very quickly, but the behavior of 5.x simply was not intuitive.
To avoid creating so many joins, and also in general, we recommend that you use lazy fetching i.e. `@ManyToOne(fetch = FetchType.LAZY)`
or `@OneToOne(fetch = FetchType.LAZY)` for most associations, but this is especially important if you have multiple self-referencing associations as you can see in the example.
=== Removal of legacy Hibernate Criteria API
The legacy Hibernate Criteria API which was deprecated back in Hibernate 5.x was removed in 6.0.
Usually, all queries using the legacy API can be modeled with the JPA Criteria API.
In some cases it is necessary to use the Hibernate JPA Criteria extensions.
=== Removal of loader walkers
The special walkers/visitors in the loader package were removed. This is now all controlled through `LoaderSelectBuilder`.
=== Restructuring of the loader package
The contents of the `loader.collection` package were restructured into `loader.ast.spi` and `loader.ast.internal`
as well as adapted to the SQM API.
The contents of `loader.custom` were adapted and moved to `query.sql`.
The contents of `loader.entity` and `loader.plan` were removed as that is now handled through `LoaderSelectBuilder`.
=== Restructuring of the sql package
The contents of `sql.ordering` were adapted and moved to `metamodel.mapping.ordering.ast`.
Classes of the `sql` package that were previously used for building SQL, but aren't needed anymore, were removed.
The SQL generation is now fully handled through the `SqlAstTranslator` which a `Dialect` exposes a factory for.
=== Changes in the type package
One of the main changes in Hibernate 6 which ripples through quite a few contracts is the change for reading by position
rather than by name from JDBC. We took this as a chance to fix-up some contracts which were named badly and cleanup
basic types in general.
==== Replace read-by-name with read-by-position
Various contracts in `org.hibernate.type` and `org.hibernate.usertype` were changed to now offer a read-by-position
method. The read-by-name methods were removed.
==== Removal of various BasicType implementations
Almost all `BasicType` implementations in `org.hibernate.type` were removed because the responsibilities these classes
had were moved to the `JdbcType` and `JavaType` contracts as well as sub-contracts like `AdjustableJdbcType`,
`VersionJavaType` and `TemporalJavaTypeDescriptor`.
The new implementation for almost all basic types is `NamedBasicTypeImpl` which just wraps a `JdbcType` and `JavaType`
along with a name.
The `StandardBasicTypes` class previously exposed `BasicType` instance fields, which now have been replaced with fields
of the type `BasicTypeReference`. APIs that previously accepted just a `BasicType` have been adapted to also accept a
`BasicTypeReference` which allows for uses of `StandardBasicType` fields to stay mostly source compatible.
==== Renaming of JavaTypeDescriptor contract
Previously the package `org.hibernate.type.descriptor.java` contained `JavaTypeDescriptor` implementations
for various basic types named with a suffix of `Type`, `JavaType` or `JavaTypeDescriptor`.
The `JavaTypeDescriptor` interface was renamed to `JavaType` and implementations were renamed to have the suffix `JavaType`.
==== Renaming of SqlTypeDescriptor contract
Previously the package `org.hibernate.type.descriptor.sql` contained `SqlTypeDescriptor` implementations
for various basic types named with a suffix of `TypeDescriptor`.
The `SqlTypeDescriptor` interface was renamed to `JdbcType` and implementations were renamed to have the suffix `JdbcType`.
The package was also changed from `org.hibernate.type.descriptor.sql` to `org.hibernate.type.descriptor.jdbc`.