Skip to content

Commit 77ae2cf

Browse files
committed
remove return value of Callback.performCallback, since it was always true and ignored
1 parent a6203b8 commit 77ae2cf

File tree

4 files changed

+30
-24
lines changed

4 files changed

+30
-24
lines changed

hibernate-core/src/main/java/org/hibernate/jpa/event/internal/EmbeddableCallback.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@
1515
import org.hibernate.resource.beans.spi.ManagedBeanRegistry;
1616

1717
/**
18-
* Represents a JPA callback on the embeddable type
18+
* Represents a JPA callback method declared by an embeddable type.
19+
*
20+
* @apiNote The JPA specification does not require that we allow
21+
* entity lifecycle callbacks on embeddable classes, and this is
22+
* at least arguably a misfeature. It would by OK to simply remove
23+
* or deprecate this.
1924
*
2025
* @author Vlad Mihalcea
2126
*/
@@ -48,18 +53,17 @@ private EmbeddableCallback(Getter embeddableGetter, Method callbackMethod, Callb
4853
}
4954

5055
@Override
51-
public boolean performCallback(Object entity) {
56+
public void performCallback(Object entity) {
5257
try {
53-
Object embeddable = embeddableGetter.get( entity );
58+
final Object embeddable = embeddableGetter.get( entity );
5459
if ( embeddable != null ) {
5560
callbackMethod.invoke( embeddable );
5661
}
57-
return true;
5862
}
5963
catch (InvocationTargetException e) {
6064
//keep runtime exceptions as is
61-
if ( e.getTargetException() instanceof RuntimeException ) {
62-
throw (RuntimeException) e.getTargetException();
65+
if ( e.getTargetException() instanceof RuntimeException runtimeException ) {
66+
throw runtimeException;
6367
}
6468
else {
6569
throw new RuntimeException( e.getTargetException() );

hibernate-core/src/main/java/org/hibernate/jpa/event/internal/EntityCallback.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import org.hibernate.resource.beans.spi.ManagedBeanRegistry;
1616

1717
/**
18-
* Represents a JPA callback on the entity itself
18+
* Represents a JPA callback method declared by the entity itself.
1919
*
2020
* @author Kabir Khan
2121
* @author Steve Ebersole
@@ -50,15 +50,14 @@ private EntityCallback(Method callbackMethod, CallbackType callbackType) {
5050
}
5151

5252
@Override
53-
public boolean performCallback(Object entity) {
53+
public void performCallback(Object entity) {
5454
try {
5555
callbackMethod.invoke( entity );
56-
return true;
5756
}
5857
catch (InvocationTargetException e) {
5958
//keep runtime exceptions as is
60-
if ( e.getTargetException() instanceof RuntimeException ) {
61-
throw (RuntimeException) e.getTargetException();
59+
if ( e.getTargetException() instanceof RuntimeException runtimeException ) {
60+
throw runtimeException;
6261
}
6362
else {
6463
throw new RuntimeException( e.getTargetException() );

hibernate-core/src/main/java/org/hibernate/jpa/event/internal/ListenerCallback.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
import org.hibernate.resource.beans.spi.ManagedBeanRegistry;
1616

1717
/**
18-
* Represents a JPA callback using a dedicated listener
18+
* Represents a JPA callback method declared by an entity listener class.
19+
*
20+
* @see jakarta.persistence.EntityListeners
1921
*
2022
* @author Kabir Khan
2123
* @author Steve Ebersole
@@ -49,15 +51,14 @@ public Callback createCallback(ManagedBeanRegistry beanRegistry) {
4951
}
5052

5153
@Override
52-
public boolean performCallback(Object entity) {
54+
public void performCallback(Object entity) {
5355
try {
5456
callbackMethod.invoke( listenerManagedBean.getBeanInstance(), entity );
55-
return true;
5657
}
5758
catch (InvocationTargetException e) {
5859
//keep runtime exceptions as is
59-
if ( e.getTargetException() instanceof RuntimeException ) {
60-
throw (RuntimeException) e.getTargetException();
60+
if ( e.getTargetException() instanceof RuntimeException runtimeException ) {
61+
throw runtimeException;
6162
}
6263
else {
6364
throw new RuntimeException( e.getTargetException() );

hibernate-core/src/main/java/org/hibernate/jpa/event/spi/Callback.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@
77
import java.io.Serializable;
88

99
/**
10-
* Represents a JPA event callback (the method).
11-
*
12-
* Generally there are 2 flavors of this; either an annotated method on the entity itself
13-
* or an annotated method on a separate "listener" class. This contract presents
14-
* a unified abstraction for both cases
10+
* Represents a JPA entity lifecycle callback method.
11+
* <p>
12+
* There are two flavors of this, which we abstract here:
13+
* <ul>
14+
* <li>an annotated method of the entity class itself, or
15+
* <li>an annotated method of a separate <em>entity listener</em> class
16+
* identified via the {@link jakarta.persistence.EntityListeners}
17+
* annotation.
18+
* </ul>
1519
*
1620
* @author Kabir Khan
1721
* @author Steve Ebersole
@@ -26,8 +30,6 @@ public interface Callback extends Serializable {
2630
* Contract for performing the callback
2731
*
2832
* @param entity Reference to the entity for which the callback is triggered.
29-
*
30-
* @return Did a callback actually happen?
3133
*/
32-
boolean performCallback(Object entity);
34+
void performCallback(Object entity);
3335
}

0 commit comments

Comments
 (0)