Skip to content

Commit f227a5e

Browse files
committed
deprecate obsolete exception type
1 parent d1c121b commit f227a5e

File tree

2 files changed

+19
-57
lines changed

2 files changed

+19
-57
lines changed

hibernate-core/src/main/java/org/hibernate/CallbackException.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@
88
* Intended to be thrown from {@link Interceptor} callbacks.
99
*
1010
* @implNote This is a legacy exception type from back in the day before
11-
* Hibernate moved to an unchecked exception strategy.
11+
* Hibernate moved to an unchecked exception strategy.
12+
* @deprecated Methods of {@link Interceptor} are no longer required to
13+
* throw this exception type.
1214
*
1315
* @author Gavin King
1416
*/
17+
@Deprecated(since = "7")
1518
public class CallbackException extends HibernateException {
1619
/**
1720
* Creates a CallbackException using the given underlying cause.

hibernate-core/src/main/java/org/hibernate/Interceptor.java

Lines changed: 15 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,8 @@ public interface Interceptor {
7272
* @param types The types of the entity properties, corresponding to the {@code state}.
7373
*
7474
* @return {@code true} if the user modified the {@code state} in any way.
75-
*
76-
* @throws CallbackException Thrown if the interceptor encounters any problems handling the callback.
7775
*/
78-
default boolean onLoad(Object entity, Object id, Object[] state, String[] propertyNames, Type[] types)
79-
throws CallbackException {
76+
default boolean onLoad(Object entity, Object id, Object[] state, String[] propertyNames, Type[] types) {
8077
return false;
8178
}
8279

@@ -94,13 +91,10 @@ default boolean onLoad(Object entity, Object id, Object[] state, String[] proper
9491
*
9592
* @return {@code true} if the user modified the {@code state} in any way.
9693
*
97-
* @throws CallbackException Thrown if the interceptor encounters any problems handling the callback.
98-
*
9994
* @see Session#persist(Object)
10095
* @see Session#merge(Object)
10196
*/
102-
default boolean onPersist(Object entity, Object id, Object[] state, String[] propertyNames, Type[] types)
103-
throws CallbackException {
97+
default boolean onPersist(Object entity, Object id, Object[] state, String[] propertyNames, Type[] types) {
10498
return onSave(entity, id, state, propertyNames, types);
10599
}
106100

@@ -115,12 +109,9 @@ default boolean onPersist(Object entity, Object id, Object[] state, String[] pro
115109
* @param propertyNames The names of the entity properties.
116110
* @param types The types of the entity properties
117111
*
118-
* @throws CallbackException Thrown if the interceptor encounters any problems handling the callback.
119-
*
120112
* @see Session#remove(Object)
121113
*/
122-
default void onRemove(Object entity, Object id, Object[] state, String[] propertyNames, Type[] types)
123-
throws CallbackException {
114+
default void onRemove(Object entity, Object id, Object[] state, String[] propertyNames, Type[] types) {
124115
onDelete(entity, id, state, propertyNames, types);
125116
}
126117

@@ -143,8 +134,6 @@ default void onRemove(Object entity, Object id, Object[] state, String[] propert
143134
*
144135
* @return {@code true} if the user modified the {@code currentState} in any way.
145136
*
146-
* @throws CallbackException Thrown if the interceptor encounters any problems handling the callback.
147-
*
148137
* @see Session#flush()
149138
*/
150139
default boolean onFlushDirty(
@@ -153,7 +142,7 @@ default boolean onFlushDirty(
153142
Object[] currentState,
154143
Object[] previousState,
155144
String[] propertyNames,
156-
Type[] types) throws CallbackException {
145+
Type[] types) {
157146
return false;
158147
}
159148

@@ -171,16 +160,13 @@ default boolean onFlushDirty(
171160
*
172161
* @return {@code true} if the user modified the {@code state} in any way.
173162
*
174-
* @throws CallbackException Thrown if the interceptor encounters any problems handling the callback.
175-
*
176163
* @see Session#persist(Object)
177164
* @see Session#merge(Object)
178165
*
179166
* @deprecated Use {@link #onPersist(Object, Object, Object[], String[], Type[])}
180167
*/
181168
@Deprecated(since = "6.6")
182-
default boolean onSave(Object entity, Object id, Object[] state, String[] propertyNames, Type[] types)
183-
throws CallbackException {
169+
default boolean onSave(Object entity, Object id, Object[] state, String[] propertyNames, Type[] types) {
184170
return false;
185171
}
186172

@@ -195,67 +181,54 @@ default boolean onSave(Object entity, Object id, Object[] state, String[] proper
195181
* @param propertyNames The names of the entity properties.
196182
* @param types The types of the entity properties
197183
*
198-
* @throws CallbackException Thrown if the interceptor encounters any problems handling the callback.
199-
*
200184
* @see Session#remove(Object)
201185
*
202186
* @deprecated Use {@link #onRemove(Object, Object, Object[], String[], Type[])}
203187
*/
204188
@Deprecated(since = "6.6")
205-
default void onDelete(Object entity, Object id, Object[] state, String[] propertyNames, Type[] types)
206-
throws CallbackException {
189+
default void onDelete(Object entity, Object id, Object[] state, String[] propertyNames, Type[] types) {
207190
}
208191

209192
/**
210193
* Called before a collection is (re)created.
211194
*
212195
* @param collection The collection instance.
213196
* @param key The collection key value.
214-
*
215-
* @throws CallbackException Thrown if the interceptor encounters any problems handling the callback.
216197
*/
217-
default void onCollectionRecreate(Object collection, Object key) throws CallbackException {
198+
default void onCollectionRecreate(Object collection, Object key) {
218199
}
219200

220201
/**
221202
* Called before a collection is deleted.
222203
*
223204
* @param collection The collection instance.
224205
* @param key The collection key value.
225-
*
226-
* @throws CallbackException Thrown if the interceptor encounters any problems handling the callback.
227206
*/
228-
default void onCollectionRemove(Object collection, Object key) throws CallbackException {
207+
default void onCollectionRemove(Object collection, Object key) {
229208
}
230209

231210
/**
232211
* Called before a collection is updated.
233212
*
234213
* @param collection The collection instance.
235214
* @param key The collection key value.
236-
*
237-
* @throws CallbackException Thrown if the interceptor encounters any problems handling the callback.
238215
*/
239-
default void onCollectionUpdate(Object collection, Object key) throws CallbackException {
216+
default void onCollectionUpdate(Object collection, Object key) {
240217
}
241218
/**
242219
* Called before a flush.
243220
*
244221
* @param entities The entities to be flushed.
245-
*
246-
* @throws CallbackException Thrown if the interceptor encounters any problems handling the callback.
247222
*/
248-
default void preFlush(Iterator<Object> entities) throws CallbackException {}
223+
default void preFlush(Iterator<Object> entities) {}
249224

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

260233
/**
261234
* Called to distinguish between transient and detached entities. The return value determines the
@@ -290,8 +263,6 @@ default Boolean isTransient(Object entity) {
290263
* @param types The types of the entity properties
291264
*
292265
* @return array of dirty property indices or {@code null} to indicate Hibernate should perform default behaviour
293-
*
294-
* @throws CallbackException Thrown if the interceptor encounters any problems handling the callback.
295266
*/
296267
default int[] findDirty(
297268
Object entity,
@@ -311,7 +282,7 @@ default int[] findDirty(
311282
default Object instantiate(
312283
String entityName,
313284
EntityRepresentationStrategy representationStrategy,
314-
Object id) throws CallbackException {
285+
Object id) {
315286
return instantiate( entityName, representationStrategy.getMode(), id );
316287
}
317288

@@ -323,7 +294,7 @@ default Object instantiate(
323294
default Object instantiate(
324295
String entityName,
325296
RepresentationMode representationMode,
326-
Object id) throws CallbackException {
297+
Object id) {
327298
return null;
328299
}
329300

@@ -334,11 +305,9 @@ default Object instantiate(
334305
*
335306
* @return the name of the entity
336307
*
337-
* @throws CallbackException Thrown if the interceptor encounters any problems handling the callback.
338-
*
339308
* @see EntityNameResolver
340309
*/
341-
default String getEntityName(Object object) throws CallbackException {
310+
default String getEntityName(Object object) {
342311
return null;
343312
}
344313

@@ -349,10 +318,8 @@ default String getEntityName(Object object) throws CallbackException {
349318
* @param id the instance identifier
350319
*
351320
* @return a fully initialized entity
352-
*
353-
* @throws CallbackException Thrown if the interceptor encounters any problems handling the callback.
354321
*/
355-
default Object getEntity(String entityName, Object id) throws CallbackException {
322+
default Object getEntity(String entityName, Object id) {
356323
return null;
357324
}
358325

@@ -388,8 +355,6 @@ default void afterTransactionCompletion(Transaction tx) {}
388355
* @param propertyNames The names of the entity properties.
389356
* @param propertyTypes The types of the entity properties
390357
*
391-
* @throws CallbackException Thrown if the interceptor encounters any problems handling the callback.
392-
*
393358
* @see StatelessSession#insert(Object)
394359
*/
395360
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
403368
* @param propertyNames The names of the entity properties.
404369
* @param propertyTypes The types of the entity properties
405370
*
406-
* @throws CallbackException Thrown if the interceptor encounters any problems handling the callback.
407-
*
408371
* @see StatelessSession#update(Object)
409372
*/
410373
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
418381
* @param propertyNames The names of the entity properties.
419382
* @param propertyTypes The types of the entity properties
420383
*
421-
* @throws CallbackException Thrown if the interceptor encounters any problems handling the callback.
422-
*
423384
* @see StatelessSession#upsert(String, Object)
424385
*/
425386
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
432393
* @param propertyNames The names of the entity properties.
433394
* @param propertyTypes The types of the entity properties
434395
*
435-
* @throws CallbackException Thrown if the interceptor encounters any problems handling the callback.
436-
*
437396
* @see StatelessSession#delete(Object)
438397
*/
439398
default void onDelete(Object entity, Object id, String[] propertyNames, Type[] propertyTypes) {}

0 commit comments

Comments
 (0)