Skip to content

Commit 0ac461f

Browse files
committed
#47184 hibernate-orm, replaced remaining occurrences of deprecated EmptyInterceptor with Interceptor
1 parent f206fa8 commit 0ac461f

File tree

5 files changed

+17
-22
lines changed

5 files changed

+17
-22
lines changed

docs/src/main/asciidoc/hibernate-orm.adoc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,9 +1435,9 @@ to your `SessionFactory` by simply defining a CDI bean with the appropriate qual
14351435
[source,java]
14361436
----
14371437
@PersistenceUnitExtension // <1>
1438-
public static class MyInterceptor extends EmptyInterceptor { // <2>
1438+
public static class MyInterceptor implements Interceptor, Serializable { // <2>
14391439
@Override
1440-
public boolean onLoad(Object entity, Serializable id, Object[] state, // <3>
1440+
public boolean onLoad(Object entity, Object id, Object[] state, // <3>
14411441
String[] propertyNames, Type[] types) {
14421442
// ...
14431443
return false;
@@ -1448,8 +1448,7 @@ public static class MyInterceptor extends EmptyInterceptor { // <2>
14481448
to tell Quarkus it should be used in the default persistence unit.
14491449
+
14501450
For <<multiple-persistence-units,named persistence units>>, use `@PersistenceUnitExtension("nameOfYourPU")`
1451-
<2> Either extend `org.hibernate.EmptyInterceptor` or implement `org.hibernate.Interceptor` directly.
1452-
<3> Implement methods as necessary.
1451+
<2> Implement methods of `org.hibernate.Interceptor` as necessary.
14531452

14541453
[TIP]
14551454
====

extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/interceptor/ApplicationScopedInterceptorTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import static org.assertj.core.api.Assertions.assertThat;
44

5-
import java.io.Serializable;
65
import java.util.ArrayList;
76
import java.util.Collections;
87
import java.util.List;
@@ -14,7 +13,7 @@
1413
import jakarta.persistence.Table;
1514
import jakarta.transaction.UserTransaction;
1615

17-
import org.hibernate.EmptyInterceptor;
16+
import org.hibernate.Interceptor;
1817
import org.hibernate.Session;
1918
import org.hibernate.SessionFactory;
2019
import org.hibernate.type.Type;
@@ -113,7 +112,7 @@ public MyEntity(int id) {
113112
}
114113

115114
@PersistenceUnitExtension // @ApplicationScoped is the default
116-
public static class ApplicationScopedInterceptor extends EmptyInterceptor {
115+
public static class ApplicationScopedInterceptor implements Interceptor {
117116
private static final List<ApplicationScopedInterceptor> instances = Collections.synchronizedList(new ArrayList<>());
118117
private static final List<Object> loadedIds = Collections.synchronizedList(new ArrayList<>());
119118

@@ -124,7 +123,7 @@ public ApplicationScopedInterceptor() {
124123
}
125124

126125
@Override
127-
public boolean onLoad(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) {
126+
public boolean onLoad(Object entity, Object id, Object[] state, String[] propertyNames, Type[] types) {
128127
loadedIds.add(id);
129128
return false;
130129
}

extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/interceptor/DependentInterceptorTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import static org.assertj.core.api.Assertions.assertThat;
44

5-
import java.io.Serializable;
65
import java.util.ArrayList;
76
import java.util.Collections;
87
import java.util.List;
@@ -15,7 +14,7 @@
1514
import jakarta.persistence.Table;
1615
import jakarta.transaction.UserTransaction;
1716

18-
import org.hibernate.EmptyInterceptor;
17+
import org.hibernate.Interceptor;
1918
import org.hibernate.Session;
2019
import org.hibernate.SessionFactory;
2120
import org.hibernate.type.Type;
@@ -116,7 +115,7 @@ public MyEntity(int id) {
116115

117116
@PersistenceUnitExtension
118117
@Dependent
119-
public static class DependentInterceptor extends EmptyInterceptor {
118+
public static class DependentInterceptor implements Interceptor {
120119
private static final List<DependentInterceptor> instances = Collections.synchronizedList(new ArrayList<>());
121120
private static final List<Object> loadedIds = Collections.synchronizedList(new ArrayList<>());
122121

@@ -127,7 +126,7 @@ public DependentInterceptor() {
127126
}
128127

129128
@Override
130-
public boolean onLoad(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) {
129+
public boolean onLoad(Object entity, Object id, Object[] state, String[] propertyNames, Type[] types) {
131130
loadedIds.add(id);
132131
return false;
133132
}

extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/interceptor/TransactionScopedInterceptorTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import static org.assertj.core.api.Assertions.assertThat;
44
import static org.assertj.core.api.Assertions.assertThatThrownBy;
55

6-
import java.io.Serializable;
76
import java.util.ArrayList;
87
import java.util.Collections;
98
import java.util.List;
@@ -16,7 +15,7 @@
1615
import jakarta.transaction.TransactionScoped;
1716
import jakarta.transaction.UserTransaction;
1817

19-
import org.hibernate.EmptyInterceptor;
18+
import org.hibernate.Interceptor;
2019
import org.hibernate.Session;
2120
import org.hibernate.SessionFactory;
2221
import org.hibernate.type.Type;
@@ -118,7 +117,7 @@ public MyEntity(int id) {
118117

119118
@PersistenceUnitExtension
120119
@TransactionScoped
121-
public static class TransactionScopedInterceptor extends EmptyInterceptor {
120+
public static class TransactionScopedInterceptor implements Interceptor {
122121
private static final List<TransactionScopedInterceptor> instances = Collections.synchronizedList(new ArrayList<>());
123122
private static final List<Object> loadedIds = Collections.synchronizedList(new ArrayList<>());
124123

@@ -129,7 +128,7 @@ public TransactionScopedInterceptor() {
129128
}
130129

131130
@Override
132-
public boolean onLoad(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) {
131+
public boolean onLoad(Object entity, Object id, Object[] state, String[] propertyNames, Type[] types) {
133132
loadedIds.add(id);
134133
return false;
135134
}

extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/multiplepersistenceunits/MultiplePersistenceUnitsInterceptorTest.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22

33
import static org.assertj.core.api.Assertions.assertThat;
44

5-
import java.io.Serializable;
65
import java.util.ArrayList;
76
import java.util.Collections;
87
import java.util.List;
98

109
import jakarta.inject.Inject;
1110
import jakarta.transaction.UserTransaction;
1211

13-
import org.hibernate.EmptyInterceptor;
12+
import org.hibernate.Interceptor;
1413
import org.hibernate.Session;
1514
import org.hibernate.type.Type;
1615
import org.junit.jupiter.api.BeforeEach;
@@ -105,7 +104,7 @@ public void test() throws Exception {
105104
}
106105

107106
@PersistenceUnitExtension
108-
public static class MyDefaultPUInterceptor extends EmptyInterceptor {
107+
public static class MyDefaultPUInterceptor implements Interceptor {
109108
private static final List<MyDefaultPUInterceptor> instances = Collections.synchronizedList(new ArrayList<>());
110109
private static final List<Object> loadedIds = Collections.synchronizedList(new ArrayList<>());
111110

@@ -116,14 +115,14 @@ public MyDefaultPUInterceptor() {
116115
}
117116

118117
@Override
119-
public boolean onLoad(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) {
118+
public boolean onLoad(Object entity, Object id, Object[] state, String[] propertyNames, Type[] types) {
120119
loadedIds.add(id);
121120
return false;
122121
}
123122
}
124123

125124
@PersistenceUnitExtension("inventory")
126-
public static class MyInventoryPUInterceptor extends EmptyInterceptor {
125+
public static class MyInventoryPUInterceptor implements Interceptor {
127126
private static final List<MyInventoryPUInterceptor> instances = Collections.synchronizedList(new ArrayList<>());
128127
private static final List<Object> loadedIds = Collections.synchronizedList(new ArrayList<>());
129128

@@ -134,7 +133,7 @@ public MyInventoryPUInterceptor() {
134133
}
135134

136135
@Override
137-
public boolean onLoad(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) {
136+
public boolean onLoad(Object entity, Object id, Object[] state, String[] propertyNames, Type[] types) {
138137
loadedIds.add(id);
139138
return false;
140139
}

0 commit comments

Comments
 (0)