8
8
9
9
import org .hibernate .boot .jaxb .mapping .spi .JaxbEntityListenerImpl ;
10
10
import org .hibernate .boot .jaxb .mapping .spi .JaxbPersistenceUnitDefaultsImpl ;
11
+ import org .hibernate .boot .models .JpaAnnotations ;
11
12
import org .hibernate .internal .util .MutableObject ;
12
13
import org .hibernate .models .ModelsException ;
13
14
import org .hibernate .models .spi .ClassDetails ;
14
15
import org .hibernate .models .spi .MethodDetails ;
16
+ import org .hibernate .models .spi .MutableMemberDetails ;
17
+ import org .hibernate .models .spi .SourceModelBuildingContext ;
15
18
16
19
import jakarta .persistence .PostLoad ;
17
20
import jakarta .persistence .PostPersist ;
22
25
import jakarta .persistence .PreUpdate ;
23
26
24
27
/**
25
- * JPA-style event listener with support for resolving callback methods
26
- * {@linkplain #from(JpaEventListenerStyle, ClassDetails, JaxbEntityListenerImpl) by name} (from XML)
27
- * or by {@linkplain #from(JpaEventListenerStyle, ClassDetails) annotation}.
28
- *
28
+ * JPA-style event listener with support for resolving callback methods from
29
+ * {@linkplain #from(JpaEventListenerStyle, ClassDetails, JaxbEntityListenerImpl, SourceModelBuildingContext) XML}
30
+ * or from {@linkplain #from(JpaEventListenerStyle, ClassDetails) annotation}.
31
+ * <p/>
29
32
* Represents a global entity listener defined in the persistence unit
30
33
*
31
34
* @see JaxbPersistenceUnitDefaultsImpl#getEntityListenerContainer()
@@ -117,7 +120,8 @@ public MethodDetails getPostLoadMethod() {
117
120
public static JpaEventListener from (
118
121
JpaEventListenerStyle consumerType ,
119
122
ClassDetails listenerClassDetails ,
120
- JaxbEntityListenerImpl jaxbMapping ) {
123
+ JaxbEntityListenerImpl jaxbMapping ,
124
+ SourceModelBuildingContext modelsContext ) {
121
125
final MutableObject <MethodDetails > prePersistMethod = new MutableObject <>();
122
126
final MutableObject <MethodDetails > postPersistMethod = new MutableObject <>();
123
127
final MutableObject <MethodDetails > preRemoveMethod = new MutableObject <>();
@@ -135,36 +139,78 @@ public static JpaEventListener from(
135
139
&& methodDetails .getName ().equals ( jaxbMapping .getPrePersist ().getMethodName () )
136
140
&& matchesSignature ( consumerType , methodDetails ) ) {
137
141
prePersistMethod .set ( methodDetails );
142
+ ( (MutableMemberDetails ) methodDetails ).addAnnotationUsage (
143
+ JpaAnnotations .PRE_PERSIST .createUsage (
144
+ methodDetails ,
145
+ modelsContext
146
+ )
147
+ );
138
148
}
139
149
else if ( jaxbMapping .getPostPersist () != null
140
150
&& methodDetails .getName ().equals ( jaxbMapping .getPostPersist ().getMethodName () )
141
151
&& matchesSignature ( consumerType , methodDetails ) ) {
142
152
postPersistMethod .set ( methodDetails );
153
+ ( (MutableMemberDetails ) methodDetails ).addAnnotationUsage (
154
+ JpaAnnotations .POST_PERSIST .createUsage (
155
+ methodDetails ,
156
+ modelsContext
157
+ )
158
+ );
143
159
}
144
160
else if ( jaxbMapping .getPreRemove () != null
145
161
&& methodDetails .getName ().equals ( jaxbMapping .getPreRemove ().getMethodName () )
146
162
&& matchesSignature ( consumerType , methodDetails ) ) {
147
163
preRemoveMethod .set ( methodDetails );
164
+ ( (MutableMemberDetails ) methodDetails ).addAnnotationUsage (
165
+ JpaAnnotations .PRE_REMOVE .createUsage (
166
+ methodDetails ,
167
+ modelsContext
168
+ )
169
+ );
148
170
}
149
171
else if ( jaxbMapping .getPostRemove () != null
150
172
&& methodDetails .getName ().equals ( jaxbMapping .getPostRemove ().getMethodName () )
151
173
&& matchesSignature ( consumerType , methodDetails ) ) {
152
174
postRemoveMethod .set ( methodDetails );
175
+ ( (MutableMemberDetails ) methodDetails ).addAnnotationUsage (
176
+ JpaAnnotations .POST_REMOVE .createUsage (
177
+ methodDetails ,
178
+ modelsContext
179
+ )
180
+ );
153
181
}
154
182
else if ( jaxbMapping .getPreUpdate () != null
155
183
&& methodDetails .getName ().equals ( jaxbMapping .getPreUpdate ().getMethodName () )
156
184
&& matchesSignature ( consumerType , methodDetails ) ) {
157
185
preUpdateMethod .set ( methodDetails );
186
+ ( (MutableMemberDetails ) methodDetails ).addAnnotationUsage (
187
+ JpaAnnotations .PRE_UPDATE .createUsage (
188
+ methodDetails ,
189
+ modelsContext
190
+ )
191
+ );
158
192
}
159
193
else if ( jaxbMapping .getPostUpdate () != null
160
194
&& methodDetails .getName ().equals ( jaxbMapping .getPostUpdate ().getMethodName () )
161
195
&& matchesSignature ( consumerType , methodDetails ) ) {
162
196
postUpdateMethod .set ( methodDetails );
197
+ ( (MutableMemberDetails ) methodDetails ).addAnnotationUsage (
198
+ JpaAnnotations .POST_UPDATE .createUsage (
199
+ methodDetails ,
200
+ modelsContext
201
+ )
202
+ );
163
203
}
164
204
else if ( jaxbMapping .getPostLoad () != null
165
205
&& methodDetails .getName ().equals ( jaxbMapping .getPostLoad ().getMethodName () )
166
206
&& matchesSignature ( consumerType , methodDetails ) ) {
167
207
postLoadMethod .set ( methodDetails );
208
+ ( (MutableMemberDetails ) methodDetails ).addAnnotationUsage (
209
+ JpaAnnotations .POST_LOAD .createUsage (
210
+ methodDetails ,
211
+ modelsContext
212
+ )
213
+ );
168
214
}
169
215
} );
170
216
0 commit comments