Skip to content

Commit 03e7b0b

Browse files
committed
HHH-18049 - Handle <exclude-default-listeners/> and <exclude-superclass-listeners/>
1 parent 2a1fb8a commit 03e7b0b

File tree

22 files changed

+705
-88
lines changed

22 files changed

+705
-88
lines changed

hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/ManagedTypeProcessor.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -844,19 +844,12 @@ public static void processOverrideMappedSuperclass(List<XmlProcessingResult.Over
844844
}
845845

846846
private static void processEntityOrMappedSuperclass(
847-
JaxbEntityOrMappedSuperclass jaxbEntity,
847+
JaxbEntityOrMappedSuperclass jaxbClass,
848848
MutableClassDetails classDetails,
849849
XmlDocumentContext xmlDocumentContext) {
850-
XmlAnnotationHelper.applyIdClass( jaxbEntity.getIdClass(), classDetails, xmlDocumentContext );
850+
XmlAnnotationHelper.applyIdClass( jaxbClass.getIdClass(), classDetails, xmlDocumentContext );
851851

852-
XmlAnnotationHelper.applyLifecycleCallbacks(
853-
jaxbEntity,
854-
JpaEventListenerStyle.CALLBACK,
855-
classDetails,
856-
xmlDocumentContext
857-
);
858-
859-
XmlAnnotationHelper.applyEntityListeners( jaxbEntity.getEntityListenerContainer(), classDetails, xmlDocumentContext );
852+
XmlAnnotationHelper.applyLifecycleCallbacks( jaxbClass, classDetails, xmlDocumentContext );
860853
}
861854

862855
public static void processCompleteEmbeddable(

hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/XmlAnnotationHelper.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import org.hibernate.boot.jaxb.mapping.spi.JaxbEntity;
5353
import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityListenerContainerImpl;
5454
import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityListenerImpl;
55+
import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityOrMappedSuperclass;
5556
import org.hibernate.boot.jaxb.mapping.spi.JaxbGeneratedValueImpl;
5657
import org.hibernate.boot.jaxb.mapping.spi.JaxbHbmFilterImpl;
5758
import org.hibernate.boot.jaxb.mapping.spi.JaxbIdClassImpl;
@@ -83,6 +84,7 @@
8384
import org.hibernate.boot.models.xml.internal.db.TableProcessing;
8485
import org.hibernate.boot.models.xml.spi.XmlDocument;
8586
import org.hibernate.boot.models.xml.spi.XmlDocumentContext;
87+
import org.hibernate.cfg.AvailableSettings;
8688
import org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle;
8789
import org.hibernate.internal.util.KeyedConsumer;
8890
import org.hibernate.internal.util.StringHelper;
@@ -1179,6 +1181,25 @@ static void applyIdClass(
11791181
idClassAnn.setAttributeValue( "value", idClassImpl );
11801182
}
11811183

1184+
public static void applyLifecycleCallbacks(
1185+
JaxbEntityOrMappedSuperclass jaxbClass,
1186+
MutableClassDetails classDetails,
1187+
XmlDocumentContext xmlDocumentContext) {
1188+
final SourceModelBuildingContext modelBuildingContext = xmlDocumentContext.getModelBuildingContext();
1189+
1190+
if ( jaxbClass.getExcludeDefaultListeners() != null ) {
1191+
classDetails.applyAnnotationUsage( JpaAnnotations.EXCLUDE_DEFAULT_LISTENERS, modelBuildingContext );
1192+
}
1193+
1194+
if ( jaxbClass.getExcludeSuperclassListeners() != null ) {
1195+
classDetails.applyAnnotationUsage( JpaAnnotations.EXCLUDE_SUPERCLASS_LISTENERS, modelBuildingContext );
1196+
}
1197+
1198+
applyLifecycleCallbacks( jaxbClass, JpaEventListenerStyle.CALLBACK, classDetails, xmlDocumentContext );
1199+
1200+
applyEntityListeners( jaxbClass.getEntityListenerContainer(), classDetails, xmlDocumentContext );
1201+
}
1202+
11821203
public static void applyEntityListeners(
11831204
JaxbEntityListenerContainerImpl entityListenerContainer,
11841205
MutableClassDetails classDetails,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
55
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html.
66
*/
7-
package org.hibernate.orm.test.jpa.compliance.callback.listeneroverrides;
7+
package org.hibernate.orm.test.jpa.callbacks.xml.common;
88

99
import java.util.ArrayList;
1010
import java.util.List;
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
5+
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html.
6+
*/
7+
package org.hibernate.orm.test.jpa.callbacks.xml.complete;
8+
9+
import jakarta.persistence.Entity;
10+
import jakarta.persistence.Id;
11+
import jakarta.persistence.JoinColumn;
12+
import jakarta.persistence.ManyToOne;
13+
14+
/**
15+
* @author Steve Ebersole
16+
*/
17+
@Entity
18+
public class LineItem extends LineItemSuper {
19+
@Id
20+
private Integer id;
21+
@ManyToOne
22+
@JoinColumn(name = "order_fk")
23+
private Order order;
24+
@ManyToOne
25+
@JoinColumn(name = "product_fk")
26+
private Product product;
27+
28+
public LineItem() {
29+
}
30+
31+
public LineItem(Integer id, Order order, Product product, int quantity) {
32+
super( quantity );
33+
this.id = id;
34+
this.order = order;
35+
this.product = product;
36+
}
37+
38+
public Integer getId() {
39+
return id;
40+
}
41+
42+
public void setId(Integer id) {
43+
this.id = id;
44+
}
45+
46+
public Order getOrder() {
47+
return order;
48+
}
49+
50+
public void setOrder(Order order) {
51+
this.order = order;
52+
}
53+
54+
public Product getProduct() {
55+
return product;
56+
}
57+
58+
public void setProduct(Product product) {
59+
this.product = product;
60+
}
61+
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
55
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html.
66
*/
7-
package org.hibernate.orm.test.jpa.compliance.callback.listeneroverrides;
7+
package org.hibernate.orm.test.jpa.callbacks.xml.complete;
8+
9+
import org.hibernate.orm.test.jpa.callbacks.xml.common.CallbackTarget;
810

9-
import jakarta.persistence.EntityListeners;
1011
import jakarta.persistence.MappedSuperclass;
1112

1213
/**
1314
* @author Steve Ebersole
1415
*/
1516
@MappedSuperclass
16-
@EntityListeners({ListenerA.class, ListenerB.class})
1717
public class LineItemSuper extends CallbackTarget {
1818
private int quantity;
1919

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
5+
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html.
6+
*/
7+
package org.hibernate.orm.test.jpa.callbacks.xml.complete;
8+
9+
import org.hibernate.orm.test.jpa.callbacks.xml.common.CallbackTarget;
10+
11+
/**
12+
* @author Steve Ebersole
13+
*/
14+
public class ListenerA {
15+
public static final String NAME = "ListenerA";
16+
17+
protected void prePersist(CallbackTarget target) {
18+
target.prePersistCalled( NAME );
19+
}
20+
21+
protected void postPersist(CallbackTarget target) {
22+
target.postPersistCalled( NAME );
23+
}
24+
25+
protected void preRemove(CallbackTarget target) {
26+
target.preRemoveCalled( NAME );
27+
}
28+
29+
protected void postRemove(CallbackTarget target) {
30+
target.postRemoveCalled( NAME );
31+
}
32+
33+
protected void preUpdate(CallbackTarget target) {
34+
target.preUpdateCalled( NAME );
35+
}
36+
37+
protected void postUpdate(CallbackTarget target) {
38+
target.postUpdateCalled( NAME );
39+
}
40+
41+
protected void postLoad(CallbackTarget target) {
42+
target.postLoadCalled( NAME );
43+
}
44+
45+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
5+
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html.
6+
*/
7+
package org.hibernate.orm.test.jpa.callbacks.xml.complete;
8+
9+
import org.hibernate.orm.test.jpa.callbacks.xml.common.CallbackTarget;
10+
11+
/**
12+
* @author Steve Ebersole
13+
*/
14+
public class ListenerB {
15+
public static final String NAME = "ListenerB";
16+
17+
protected void prePersist(CallbackTarget target) {
18+
target.prePersistCalled( NAME );
19+
}
20+
21+
protected void postPersist(CallbackTarget target) {
22+
target.postPersistCalled( NAME );
23+
}
24+
25+
protected void preRemove(CallbackTarget target) {
26+
target.preRemoveCalled( NAME );
27+
}
28+
29+
protected void postRemove(CallbackTarget target) {
30+
target.postRemoveCalled( NAME );
31+
}
32+
33+
protected void preUpdate(CallbackTarget target) {
34+
target.preUpdateCalled( NAME );
35+
}
36+
37+
protected void postUpdate(CallbackTarget target) {
38+
target.postUpdateCalled( NAME );
39+
}
40+
41+
protected void postLoad(CallbackTarget target) {
42+
target.postLoadCalled( NAME );
43+
}
44+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
5+
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html.
6+
*/
7+
package org.hibernate.orm.test.jpa.callbacks.xml.complete;
8+
9+
import org.hibernate.orm.test.jpa.callbacks.xml.common.CallbackTarget;
10+
11+
/**
12+
* @author Steve Ebersole
13+
*/
14+
public class ListenerC {
15+
public static final String NAME = "ListenerC";
16+
17+
protected void prePersist(CallbackTarget target) {
18+
target.prePersistCalled( NAME );
19+
}
20+
21+
protected void postPersist(CallbackTarget target) {
22+
target.postPersistCalled( NAME );
23+
}
24+
25+
protected void preRemove(CallbackTarget target) {
26+
target.preRemoveCalled( NAME );
27+
}
28+
29+
protected void postRemove(CallbackTarget target) {
30+
target.postRemoveCalled( NAME );
31+
}
32+
33+
protected void preUpdate(CallbackTarget target) {
34+
target.preUpdateCalled( NAME );
35+
}
36+
37+
protected void postUpdate(CallbackTarget target) {
38+
target.postUpdateCalled( NAME );
39+
}
40+
41+
protected void postLoad(CallbackTarget target) {
42+
target.postLoadCalled( NAME );
43+
}
44+
45+
}

0 commit comments

Comments
 (0)