diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SybaseASELegacyDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SybaseASELegacyDialect.java index d3ed608c1350..2dd477e1d73f 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SybaseASELegacyDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SybaseASELegacyDialect.java @@ -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; @@ -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; @@ -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": @@ -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": diff --git a/hibernate-core/src/main/java/org/hibernate/AssertionFailure.java b/hibernate-core/src/main/java/org/hibernate/AssertionFailure.java index fbf6bda56634..fecf27dc1349 100644 --- a/hibernate-core/src/main/java/org/hibernate/AssertionFailure.java +++ b/hibernate-core/src/main/java/org/hibernate/AssertionFailure.java @@ -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 ); diff --git a/hibernate-core/src/main/java/org/hibernate/CallbackException.java b/hibernate-core/src/main/java/org/hibernate/CallbackException.java index bd0e7ee6d69b..11452f950e9b 100644 --- a/hibernate-core/src/main/java/org/hibernate/CallbackException.java +++ b/hibernate-core/src/main/java/org/hibernate/CallbackException.java @@ -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. diff --git a/hibernate-core/src/main/java/org/hibernate/Interceptor.java b/hibernate-core/src/main/java/org/hibernate/Interceptor.java index 5dda50d163d2..3412a5d1be88 100644 --- a/hibernate-core/src/main/java/org/hibernate/Interceptor.java +++ b/hibernate-core/src/main/java/org/hibernate/Interceptor.java @@ -72,11 +72,8 @@ public interface Interceptor { * @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) { return false; } @@ -94,13 +91,10 @@ default boolean onLoad(Object entity, Object id, Object[] state, String[] proper * * @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); } @@ -115,12 +109,9 @@ default boolean onPersist(Object entity, Object id, Object[] state, String[] pro * @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); } @@ -143,8 +134,6 @@ default void onRemove(Object entity, Object id, Object[] state, String[] propert * * @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( @@ -153,7 +142,7 @@ default boolean onFlushDirty( Object[] currentState, Object[] previousState, String[] propertyNames, - Type[] types) throws CallbackException { + Type[] types) { return false; } @@ -171,16 +160,13 @@ default boolean onFlushDirty( * * @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) { return false; } @@ -195,15 +181,12 @@ default boolean onSave(Object entity, Object id, Object[] state, String[] proper * @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) { } /** @@ -211,10 +194,8 @@ default void onDelete(Object entity, Object id, Object[] state, String[] propert * * @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) { } /** @@ -222,10 +203,8 @@ default void onCollectionRecreate(Object collection, Object key) throws Callback * * @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) { } /** @@ -233,29 +212,23 @@ default void onCollectionRemove(Object collection, Object key) throws CallbackEx * * @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 entities) throws CallbackException {} + default void preFlush(Iterator entities) {} /** * 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 entities) throws CallbackException {} + default void postFlush(Iterator entities) {} /** * Called to distinguish between transient and detached entities. The return value determines the @@ -290,8 +263,6 @@ default Boolean isTransient(Object entity) { * @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, @@ -311,7 +282,7 @@ default int[] findDirty( default Object instantiate( String entityName, EntityRepresentationStrategy representationStrategy, - Object id) throws CallbackException { + Object id) { return instantiate( entityName, representationStrategy.getMode(), id ); } @@ -323,7 +294,7 @@ default Object instantiate( default Object instantiate( String entityName, RepresentationMode representationMode, - Object id) throws CallbackException { + Object id) { return null; } @@ -334,11 +305,9 @@ default Object instantiate( * * @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) { return null; } @@ -349,10 +318,8 @@ default String getEntityName(Object object) throws CallbackException { * @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) { return null; } @@ -388,8 +355,6 @@ default void afterTransactionCompletion(Transaction tx) {} * @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) {} @@ -403,8 +368,6 @@ default void onInsert(Object entity, Object id, Object[] state, String[] propert * @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) {} @@ -418,8 +381,6 @@ default void onUpdate(Object entity, Object id, Object[] state, String[] propert * @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) {} @@ -432,8 +393,6 @@ default void onUpsert(Object entity, Object id, Object[] state, String[] propert * @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) {} diff --git a/hibernate-core/src/main/java/org/hibernate/LazyInitializationException.java b/hibernate-core/src/main/java/org/hibernate/LazyInitializationException.java index c9c3591d2fed..775761898d45 100644 --- a/hibernate-core/src/main/java/org/hibernate/LazyInitializationException.java +++ b/hibernate-core/src/main/java/org/hibernate/LazyInitializationException.java @@ -19,6 +19,8 @@ * * @see Hibernate#initialize(Object) * @see Hibernate#isInitialized(Object) + * @see StatelessSession#fetch(Object) + * * @author Gavin King */ public class LazyInitializationException extends HibernateException { diff --git a/hibernate-core/src/main/java/org/hibernate/NonUniqueResultException.java b/hibernate-core/src/main/java/org/hibernate/NonUniqueResultException.java index 69df0d053e1c..879594b863ab 100644 --- a/hibernate-core/src/main/java/org/hibernate/NonUniqueResultException.java +++ b/hibernate-core/src/main/java/org/hibernate/NonUniqueResultException.java @@ -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 { diff --git a/hibernate-core/src/main/java/org/hibernate/PropertySetterAccessException.java b/hibernate-core/src/main/java/org/hibernate/PropertySetterAccessException.java index 6f2ea96b9fbb..e79340815421 100644 --- a/hibernate-core/src/main/java/org/hibernate/PropertySetterAccessException.java +++ b/hibernate-core/src/main/java/org/hibernate/PropertySetterAccessException.java @@ -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 { diff --git a/hibernate-core/src/main/java/org/hibernate/QueryTimeoutException.java b/hibernate-core/src/main/java/org/hibernate/QueryTimeoutException.java index 454354672e1d..8c5503cb1c1c 100644 --- a/hibernate-core/src/main/java/org/hibernate/QueryTimeoutException.java +++ b/hibernate-core/src/main/java/org/hibernate/QueryTimeoutException.java @@ -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 { /** diff --git a/hibernate-core/src/main/java/org/hibernate/UnknownEntityTypeException.java b/hibernate-core/src/main/java/org/hibernate/UnknownEntityTypeException.java index 3a5ba0d13f1a..55d579dc81e7 100644 --- a/hibernate-core/src/main/java/org/hibernate/UnknownEntityTypeException.java +++ b/hibernate-core/src/main/java/org/hibernate/UnknownEntityTypeException.java @@ -6,7 +6,7 @@ /** * Indicates an attempt was made to refer to an unknown entity name or class. - *

+ * * @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. diff --git a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/internal/FileXmlSource.java b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/internal/FileXmlSource.java index 87bf044367c3..90a04a9ffb66 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/internal/FileXmlSource.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/internal/FileXmlSource.java @@ -26,11 +26,11 @@ public FileXmlSource(Origin origin, File file) { } @Override - public Binding doBind(Binder binder) { + public Binding doBind(Binder binder) { return doBind( binder, file, getOrigin() ); } - public static Binding doBind(Binder binder, File file, Origin origin) { + public static Binding doBind(Binder binder, File file, Origin origin) { final FileInputStream fis; try { fis = new FileInputStream( file ); diff --git a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/internal/InputStreamXmlSource.java b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/internal/InputStreamXmlSource.java index 2030e903b8ab..c7ad607f2ec4 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/internal/InputStreamXmlSource.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/internal/InputStreamXmlSource.java @@ -32,11 +32,11 @@ public InputStreamXmlSource(Origin origin, InputStream inputStream, boolean auto } @Override - public Binding doBind(Binder binder) { + public Binding doBind(Binder binder) { return doBind( binder, inputStream, getOrigin(), autoClose ); } - public static Binding doBind(Binder binder, InputStream inputStream, Origin origin, boolean autoClose) { + public static Binding doBind(Binder binder, InputStream inputStream, Origin origin, boolean autoClose) { try { return binder.bind( inputStream, origin ); } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/internal/UrlXmlSource.java b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/internal/UrlXmlSource.java index 19995fcf91dc..97345f87fcf0 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/internal/UrlXmlSource.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/internal/UrlXmlSource.java @@ -29,7 +29,7 @@ public UrlXmlSource(Origin origin, URL url) { } @Override - public Binding doBind(Binder binder) { + public Binding doBind(Binder binder) { try { InputStream stream = url.openStream(); return InputStreamXmlSource.doBind( binder, stream, getOrigin(), true ); diff --git a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/spi/XmlSource.java b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/spi/XmlSource.java index decc1552ae6c..799567bcb319 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/spi/XmlSource.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/spi/XmlSource.java @@ -26,5 +26,5 @@ public Origin getOrigin() { return origin; } - public abstract Binding doBind(Binder binder); + public abstract Binding doBind(Binder binder); } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/spi/XmlMappingBinderAccess.java b/hibernate-core/src/main/java/org/hibernate/boot/spi/XmlMappingBinderAccess.java index ca7ea8bd3cd2..023f85b73ad0 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/spi/XmlMappingBinderAccess.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/spi/XmlMappingBinderAccess.java @@ -55,44 +55,36 @@ public MappingBinder getMappingBinder() { /** * Create a {@linkplain Binding binding} from a named URL resource */ - public Binding bind(String resource) { + public Binding bind(String resource) { LOG.tracef( "reading mappings from resource : %s", resource ); - final Origin origin = new Origin( SourceType.RESOURCE, resource ); final URL url = classLoaderService.locateResource( resource ); if ( url == null ) { throw new MappingNotFoundException( origin ); } - - //noinspection unchecked return new UrlXmlSource( origin, url ).doBind( getMappingBinder() ); } /** * Create a {@linkplain Binding binding} from a File reference */ - public Binding bind(File file) { + public Binding bind(File file) { final Origin origin = new Origin( SourceType.FILE, file.getPath() ); LOG.tracef( "reading mappings from file : %s", origin.getName() ); - if ( !file.exists() ) { throw new MappingNotFoundException( origin ); } - - //noinspection unchecked return new FileXmlSource( origin, file ).doBind( getMappingBinder() ); } /** * Create a {@linkplain Binding binding} from an input stream */ - public Binding bind(InputStreamAccess xmlInputStreamAccess) { + public Binding bind(InputStreamAccess xmlInputStreamAccess) { LOG.tracef( "reading mappings from InputStreamAccess : %s", xmlInputStreamAccess.getStreamName() ); - final Origin origin = new Origin( SourceType.INPUT_STREAM, xmlInputStreamAccess.getStreamName() ); - InputStream xmlInputStream = xmlInputStreamAccess.accessInputStream(); + final InputStream xmlInputStream = xmlInputStreamAccess.accessInputStream(); try { - //noinspection unchecked return new InputStreamXmlSource( origin, xmlInputStream, false ).doBind( mappingBinder ); } finally { @@ -108,22 +100,19 @@ public Binding bind(InputStreamAcce /** * Create a {@linkplain Binding binding} from an input stream */ - public Binding bind(InputStream xmlInputStream) { + public Binding bind(InputStream xmlInputStream) { LOG.trace( "reading mappings from InputStream" ); final Origin origin = new Origin( SourceType.INPUT_STREAM, null ); - //noinspection unchecked return new InputStreamXmlSource( origin, xmlInputStream, false ).doBind( getMappingBinder() ); } /** * Create a {@linkplain Binding binding} from a URL */ - public Binding bind(URL url) { + public Binding bind(URL url) { final String urlExternalForm = url.toExternalForm(); LOG.debugf( "Reading mapping document from URL : %s", urlExternalForm ); - final Origin origin = new Origin( SourceType.URL, urlExternalForm ); - //noinspection unchecked return new UrlXmlSource( origin, url ).doBind( getMappingBinder() ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/exception/LockTimeoutException.java b/hibernate-core/src/main/java/org/hibernate/exception/LockTimeoutException.java index d969aec3237a..53b816d78599 100644 --- a/hibernate-core/src/main/java/org/hibernate/exception/LockTimeoutException.java +++ b/hibernate-core/src/main/java/org/hibernate/exception/LockTimeoutException.java @@ -9,10 +9,13 @@ import java.sql.SQLException; /** - * A {@link JDBCException} indicating that a lock request - * timed out on the database. + * A {@link JDBCException} indicating that a {@linkplain org.hibernate.LockMode lock} + * request timed out on the database. * * @author Steve Ebersole + * + * @see org.hibernate.LockOptions#getTimeOut + * @see org.hibernate.LockOptions#setTimeOut */ public class LockTimeoutException extends LockAcquisitionException { public LockTimeoutException(String string, SQLException root) {