Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.hibernate.exception.spi.SQLExceptionConversionDelegate;
import org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtractor;
import org.hibernate.exception.spi.ViolatedConstraintNameExtractor;
import org.hibernate.internal.util.JdbcExceptionHelper;
import org.hibernate.query.sqm.IntervalType;
import org.hibernate.query.common.TemporalUnit;
import org.hibernate.service.ServiceRegistry;
Expand All @@ -50,6 +49,8 @@
import jakarta.persistence.TemporalType;

import static org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtractor.extractUsingTemplate;
import static org.hibernate.internal.util.JdbcExceptionHelper.extractErrorCode;
import static org.hibernate.internal.util.JdbcExceptionHelper.extractSqlState;
import static org.hibernate.type.SqlTypes.BIGINT;
import static org.hibernate.type.SqlTypes.BOOLEAN;
import static org.hibernate.type.SqlTypes.DATE;
Expand Down Expand Up @@ -634,8 +635,8 @@ public ViolatedConstraintNameExtractor getViolatedConstraintNameExtractor() {
*/
private static final ViolatedConstraintNameExtractor EXTRACTOR =
new TemplatedViolatedConstraintNameExtractor( sqle -> {
final String sqlState = JdbcExceptionHelper.extractSqlState( sqle );
final int errorCode = JdbcExceptionHelper.extractErrorCode( sqle );
final String sqlState = extractSqlState( sqle );
final int errorCode = extractErrorCode( sqle );
if ( sqlState != null ) {
switch ( sqlState ) {
case "S1000":
Expand All @@ -660,8 +661,8 @@ public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate() {
return null;
}
return (sqlException, message, sql) -> {
final String sqlState = JdbcExceptionHelper.extractSqlState( sqlException );
final int errorCode = JdbcExceptionHelper.extractErrorCode( sqlException );
final String sqlState = extractSqlState( sqlException );
final int errorCode = extractErrorCode( sqlException );
if ( sqlState != null ) {
switch ( sqlState ) {
case "HY008":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
* @author Gavin King
*/
public class AssertionFailure extends RuntimeException {
private static final long serialVersionUID = 1L;

private static final CoreMessageLogger LOG = CoreLogging.messageLogger( AssertionFailure.class );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@
* Intended to be thrown from {@link Interceptor} callbacks.
*
* @implNote This is a legacy exception type from back in the day before
* Hibernate moved to an unchecked exception strategy.
* Hibernate moved to an unchecked exception strategy.
* @deprecated Methods of {@link Interceptor} are no longer required to
* throw this exception type.
*
* @author Gavin King
*/
@Deprecated(since = "7")
public class CallbackException extends HibernateException {
/**
* Creates a CallbackException using the given underlying cause.
Expand Down
71 changes: 15 additions & 56 deletions hibernate-core/src/main/java/org/hibernate/Interceptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,8 @@
* @param types The types of the entity properties, corresponding to the {@code state}.
*
* @return {@code true} if the user modified the {@code state} in any way.
*
* @throws CallbackException Thrown if the interceptor encounters any problems handling the callback.
*/
default boolean onLoad(Object entity, Object id, Object[] state, String[] propertyNames, Type[] types)
throws CallbackException {
default boolean onLoad(Object entity, Object id, Object[] state, String[] propertyNames, Type[] types) {

Check notice

Code scanning / CodeQL

Useless parameter Note

The parameter 'entity' is never used.

Check notice

Code scanning / CodeQL

Useless parameter Note

The parameter 'id' is never used.

Check notice

Code scanning / CodeQL

Useless parameter Note

The parameter 'state' is never used.

Check notice

Code scanning / CodeQL

Useless parameter Note

The parameter 'propertyNames' is never used.

Check notice

Code scanning / CodeQL

Useless parameter Note

The parameter 'types' is never used.
return false;
}

Expand All @@ -94,20 +91,17 @@
*
* @return {@code true} if the user modified the {@code state} in any way.
*
* @throws CallbackException Thrown if the interceptor encounters any problems handling the callback.
*
* @see Session#persist(Object)
* @see Session#merge(Object)
*/
default boolean onPersist(Object entity, Object id, Object[] state, String[] propertyNames, Type[] types)
throws CallbackException {
default boolean onPersist(Object entity, Object id, Object[] state, String[] propertyNames, Type[] types) {
return onSave(entity, id, state, propertyNames, types);
}

/**
* Called before an object is removed by a stateful session.
* <p>
* It is not recommended that the interceptor modify the {@code state}.

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note

Invoking
Interceptor.onSave
should be avoided because it has been deprecated.
*
* @param entity The entity instance being deleted
* @param id The identifier of the entity
Expand All @@ -115,12 +109,9 @@
* @param propertyNames The names of the entity properties.
* @param types The types of the entity properties
*
* @throws CallbackException Thrown if the interceptor encounters any problems handling the callback.
*
* @see Session#remove(Object)
*/
default void onRemove(Object entity, Object id, Object[] state, String[] propertyNames, Type[] types)
throws CallbackException {
default void onRemove(Object entity, Object id, Object[] state, String[] propertyNames, Type[] types) {
onDelete(entity, id, state, propertyNames, types);
}

Expand All @@ -130,7 +121,7 @@
* Note that not all flushes end in actual synchronization with the database, in which case the
* new {@code currentState} will be propagated to the object, but not necessarily (immediately) to
* the database. It is strongly recommended that the interceptor <b>not</b> modify the {@code previousState}.
*

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note

Invoking
Interceptor.onDelete
should be avoided because it has been deprecated.
* @apiNote The indexes across the {@code currentState}, {@code previousState}, {@code propertyNames}, and
* {@code types} arrays match.
*
Expand All @@ -143,8 +134,6 @@
*
* @return {@code true} if the user modified the {@code currentState} in any way.
*
* @throws CallbackException Thrown if the interceptor encounters any problems handling the callback.
*
* @see Session#flush()
*/
default boolean onFlushDirty(
Expand All @@ -153,7 +142,7 @@
Object[] currentState,
Object[] previousState,
String[] propertyNames,
Type[] types) throws CallbackException {
Type[] types) {
return false;
}

Expand All @@ -171,16 +160,13 @@
*
* @return {@code true} if the user modified the {@code state} in any way.
*
* @throws CallbackException Thrown if the interceptor encounters any problems handling the callback.
*
* @see Session#persist(Object)
* @see Session#merge(Object)
*
* @deprecated Use {@link #onPersist(Object, Object, Object[], String[], Type[])}
*/
@Deprecated(since = "6.6")
default boolean onSave(Object entity, Object id, Object[] state, String[] propertyNames, Type[] types)
throws CallbackException {
default boolean onSave(Object entity, Object id, Object[] state, String[] propertyNames, Type[] types) {

Check notice

Code scanning / CodeQL

Useless parameter Note

The parameter 'entity' is never used.

Check notice

Code scanning / CodeQL

Useless parameter Note

The parameter 'id' is never used.

Check notice

Code scanning / CodeQL

Useless parameter Note

The parameter 'state' is never used.

Check notice

Code scanning / CodeQL

Useless parameter Note

The parameter 'propertyNames' is never used.

Check notice

Code scanning / CodeQL

Useless parameter Note

The parameter 'types' is never used.
return false;
}

Expand All @@ -195,67 +181,54 @@
* @param propertyNames The names of the entity properties.
* @param types The types of the entity properties
*
* @throws CallbackException Thrown if the interceptor encounters any problems handling the callback.
*
* @see Session#remove(Object)
*
* @deprecated Use {@link #onRemove(Object, Object, Object[], String[], Type[])}
*/
@Deprecated(since = "6.6")
default void onDelete(Object entity, Object id, Object[] state, String[] propertyNames, Type[] types)
throws CallbackException {
default void onDelete(Object entity, Object id, Object[] state, String[] propertyNames, Type[] types) {

Check notice

Code scanning / CodeQL

Useless parameter Note

The parameter 'entity' is never used.

Check notice

Code scanning / CodeQL

Useless parameter Note

The parameter 'id' is never used.

Check notice

Code scanning / CodeQL

Useless parameter Note

The parameter 'state' is never used.

Check notice

Code scanning / CodeQL

Useless parameter Note

The parameter 'propertyNames' is never used.

Check notice

Code scanning / CodeQL

Useless parameter Note

The parameter 'types' is never used.
}

/**
* Called before a collection is (re)created.
*
* @param collection The collection instance.
* @param key The collection key value.
*
* @throws CallbackException Thrown if the interceptor encounters any problems handling the callback.
*/
default void onCollectionRecreate(Object collection, Object key) throws CallbackException {
default void onCollectionRecreate(Object collection, Object key) {
}

/**
* Called before a collection is deleted.
*
* @param collection The collection instance.
* @param key The collection key value.
*
* @throws CallbackException Thrown if the interceptor encounters any problems handling the callback.
*/
default void onCollectionRemove(Object collection, Object key) throws CallbackException {
default void onCollectionRemove(Object collection, Object key) {

Check notice

Code scanning / CodeQL

Useless parameter Note

The parameter 'collection' is never used.

Check notice

Code scanning / CodeQL

Useless parameter Note

The parameter 'key' is never used.
}

/**
* Called before a collection is updated.
*
* @param collection The collection instance.
* @param key The collection key value.
*
* @throws CallbackException Thrown if the interceptor encounters any problems handling the callback.
*/
default void onCollectionUpdate(Object collection, Object key) throws CallbackException {
default void onCollectionUpdate(Object collection, Object key) {
}
/**
* Called before a flush.
*
* @param entities The entities to be flushed.
*
* @throws CallbackException Thrown if the interceptor encounters any problems handling the callback.
*/
default void preFlush(Iterator<Object> entities) throws CallbackException {}
default void preFlush(Iterator<Object> entities) {}

Check notice

Code scanning / CodeQL

Useless parameter Note

The parameter 'entities' is never used.

/**
* Called after a flush that actually ends in execution of the SQL statements required to synchronize
* in-memory state with the database.
*
* @param entities The entities that were flushed.
*
* @throws CallbackException Thrown if the interceptor encounters any problems handling the callback.
*/
default void postFlush(Iterator<Object> entities) throws CallbackException {}
default void postFlush(Iterator<Object> entities) {}

Check notice

Code scanning / CodeQL

Useless parameter Note

The parameter 'entities' is never used.

/**
* Called to distinguish between transient and detached entities. The return value determines the
Expand Down Expand Up @@ -290,8 +263,6 @@
* @param types The types of the entity properties
*
* @return array of dirty property indices or {@code null} to indicate Hibernate should perform default behaviour
*
* @throws CallbackException Thrown if the interceptor encounters any problems handling the callback.
*/
default int[] findDirty(
Object entity,
Expand All @@ -311,7 +282,7 @@
default Object instantiate(
String entityName,
EntityRepresentationStrategy representationStrategy,
Object id) throws CallbackException {
Object id) {
return instantiate( entityName, representationStrategy.getMode(), id );
}

Expand All @@ -323,7 +294,7 @@
default Object instantiate(
String entityName,
RepresentationMode representationMode,
Object id) throws CallbackException {
Object id) {
return null;
}

Expand All @@ -334,11 +305,9 @@
*
* @return the name of the entity
*
* @throws CallbackException Thrown if the interceptor encounters any problems handling the callback.
*
* @see EntityNameResolver
*/
default String getEntityName(Object object) throws CallbackException {
default String getEntityName(Object object) {

Check notice

Code scanning / CodeQL

Useless parameter Note

The parameter 'object' is never used.
return null;
}

Expand All @@ -349,10 +318,8 @@
* @param id the instance identifier
*
* @return a fully initialized entity
*
* @throws CallbackException Thrown if the interceptor encounters any problems handling the callback.
*/
default Object getEntity(String entityName, Object id) throws CallbackException {
default Object getEntity(String entityName, Object id) {

Check notice

Code scanning / CodeQL

Useless parameter Note

The parameter 'entityName' is never used.

Check notice

Code scanning / CodeQL

Useless parameter Note

The parameter 'id' is never used.
return null;
}

Expand Down Expand Up @@ -388,8 +355,6 @@
* @param propertyNames The names of the entity properties.
* @param propertyTypes The types of the entity properties
*
* @throws CallbackException Thrown if the interceptor encounters any problems handling the callback.
*
* @see StatelessSession#insert(Object)
*/
default void onInsert(Object entity, Object id, Object[] state, String[] propertyNames, Type[] propertyTypes) {}
Expand All @@ -403,8 +368,6 @@
* @param propertyNames The names of the entity properties.
* @param propertyTypes The types of the entity properties
*
* @throws CallbackException Thrown if the interceptor encounters any problems handling the callback.
*
* @see StatelessSession#update(Object)
*/
default void onUpdate(Object entity, Object id, Object[] state, String[] propertyNames, Type[] propertyTypes) {}
Expand All @@ -418,8 +381,6 @@
* @param propertyNames The names of the entity properties.
* @param propertyTypes The types of the entity properties
*
* @throws CallbackException Thrown if the interceptor encounters any problems handling the callback.
*
* @see StatelessSession#upsert(String, Object)
*/
default void onUpsert(Object entity, Object id, Object[] state, String[] propertyNames, Type[] propertyTypes) {}
Expand All @@ -432,8 +393,6 @@
* @param propertyNames The names of the entity properties.
* @param propertyTypes The types of the entity properties
*
* @throws CallbackException Thrown if the interceptor encounters any problems handling the callback.
*
* @see StatelessSession#delete(Object)
*/
default void onDelete(Object entity, Object id, String[] propertyNames, Type[] propertyTypes) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*
* @see Hibernate#initialize(Object)
* @see Hibernate#isInitialized(Object)
* @see StatelessSession#fetch(Object)
*
* @author Gavin King
*/
public class LazyInitializationException extends HibernateException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
* this one is recoverable!
*
* @author Gavin King
*
* @see jakarta.persistence.Query#getSingleResult
* @see org.hibernate.query.SelectionQuery#getSingleResult
*/
public class NonUniqueResultException extends HibernateException {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import org.checkerframework.checker.nullness.qual.Nullable;

/**
* Thrown when an {@link IllegalArgumentException} occurs calling a property setter method.
*
* @author Steve Ebersole
*/
public class PropertySetterAccessException extends PropertyAccessException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
import java.sql.SQLException;

/**
* Thrown when a database query timeout occurs.
* A {@link JDBCException} indicating that a database query timed
* out on the database.
*
* @author Scott Marlow
*
* @see jakarta.persistence.Query#setTimeout
* @see org.hibernate.query.CommonQueryContract#setTimeout
*/
public class QueryTimeoutException extends JDBCException {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

/**
* Indicates an attempt was made to refer to an unknown entity name or class.
* <p>
*
* @implNote This class extends {@link MappingException} for legacy reasons.
* Longer term I think it makes more sense to have a different hierarchy for
* runtime-"mapping" exceptions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ public FileXmlSource(Origin origin, File file) {
}

@Override
public Binding doBind(Binder binder) {
public <T> Binding<T> doBind(Binder<T> binder) {
return doBind( binder, file, getOrigin() );
}

public static Binding doBind(Binder binder, File file, Origin origin) {
public static <T> Binding<T> doBind(Binder<T> binder, File file, Origin origin) {
final FileInputStream fis;
try {
fis = new FileInputStream( file );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ public InputStreamXmlSource(Origin origin, InputStream inputStream, boolean auto
}

@Override
public Binding doBind(Binder binder) {
public <T> Binding<T> doBind(Binder<T> binder) {
return doBind( binder, inputStream, getOrigin(), autoClose );
}

public static Binding doBind(Binder binder, InputStream inputStream, Origin origin, boolean autoClose) {
public static <T> Binding<T> doBind(Binder<T> binder, InputStream inputStream, Origin origin, boolean autoClose) {
try {
return binder.bind( inputStream, origin );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public UrlXmlSource(Origin origin, URL url) {
}

@Override
public Binding doBind(Binder binder) {
public <T> Binding<T> doBind(Binder<T> binder) {
try {
InputStream stream = url.openStream();
return InputStreamXmlSource.doBind( binder, stream, getOrigin(), true );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ public Origin getOrigin() {
return origin;
}

public abstract Binding doBind(Binder binder);
public abstract <T> Binding<T> doBind(Binder<T> binder);
}
Loading