From 115e40b7b0fe64e7110dff4b03857dc45920482a Mon Sep 17 00:00:00 2001 From: "Jonathan S. Fisher" Date: Mon, 19 May 2025 11:56:04 -0500 Subject: [PATCH 1/3] [2.7] Close #1806 - Have to the ability to dynamically set the Validation Group during a transaction. Add tests, update copyright headers. --- .../config/EntityManagerProperties.java | 20 +- .../persistence.xml | 3 +- .../server/persistence.xml | 3 +- .../models/jpa/beanvalidation/Employee.java | 13 +- .../jpa/beanvalidation/GermanPhone.java | 19 ++ .../models/jpa/beanvalidation/Phone.java | 32 +++ .../models/jpa/beanvalidation/USPhone.java | 19 ++ .../BeanValidationJunitTest.java | 248 +++++++++++++++++- .../listeners/BeanValidationListener.java | 50 +++- 9 files changed, 392 insertions(+), 15 deletions(-) create mode 100644 jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa/beanvalidation/GermanPhone.java create mode 100644 jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa/beanvalidation/Phone.java create mode 100644 jpa/eclipselink.jpa.test/src/org/eclipse/persistence/testing/models/jpa/beanvalidation/USPhone.java diff --git a/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/config/EntityManagerProperties.java b/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/config/EntityManagerProperties.java index 0c673fe8aef..c453df05c48 100644 --- a/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/config/EntityManagerProperties.java +++ b/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/config/EntityManagerProperties.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2023 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2025 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at @@ -319,6 +319,21 @@ public class EntityManagerProperties { * ) */ public static final String COMPOSITE_UNIT_PROPERTIES = PersistenceUnitProperties.COMPOSITE_UNIT_PROPERTIES; + + /** + * Overrides the Bean Validation Group(s) that will execute during a prePersist event. This should be a class or class[]. + */ + public static final String VALIDATION_GROUP_PRE_PERSIST = "eclipselink.validation.group.prePersist"; + + /** + * Overrides the Bean Validation Group(s) that will execute during a preUpdate event. This should be a class or class[]. + */ + public static final String VALIDATION_GROUP_PRE_UPDATE = "eclipselink.validation.group.preUpdate"; + + /** + * Overrides the Bean Validation Group(s) that will execute during a preRemove event. This should be a class or class[]. + */ + public static final String VALIDATION_GROUP_PRE_REMOVE = "eclipselink.validation.group.preRemove"; private static final Set supportedProperties = new HashSet() { @@ -344,6 +359,9 @@ public class EntityManagerProperties { add(PERSISTENCE_CONTEXT_COMMIT_ORDER); add(FLUSH_CLEAR_CACHE); add(COMPOSITE_UNIT_PROPERTIES); + add(VALIDATION_GROUP_PRE_PERSIST); + add(VALIDATION_GROUP_PRE_UPDATE); + add(VALIDATION_GROUP_PRE_REMOVE); } }; diff --git a/jpa/eclipselink.jpa.test/resource/eclipselink-beanvalidation-model/persistence.xml b/jpa/eclipselink.jpa.test/resource/eclipselink-beanvalidation-model/persistence.xml index f0669d13b98..418b6e8bb61 100644 --- a/jpa/eclipselink.jpa.test/resource/eclipselink-beanvalidation-model/persistence.xml +++ b/jpa/eclipselink.jpa.test/resource/eclipselink-beanvalidation-model/persistence.xml @@ -1,6 +1,6 @@