Skip to content

[2.7] Close #1806 - Have to the ability to dynamically set the Validation Group during a transaction #2010

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: 2.7
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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_UPDATET = "eclipselink.beanvalidation.group.pre-persist";

/**
* 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.beanvalidation.group.pre-update";

/**
* 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.beanvalidation.group.pre-remove";

private static final Set<String> supportedProperties = new HashSet<String>() {

Expand All @@ -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);
}
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!--

Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved.
Copyright (c) 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
Expand All @@ -18,6 +18,7 @@
<class>org.eclipse.persistence.testing.models.jpa.beanvalidation.Employee</class>
<class>org.eclipse.persistence.testing.models.jpa.beanvalidation.Project</class>
<class>org.eclipse.persistence.testing.models.jpa.beanvalidation.Address</class>
<class>org.eclipse.persistence.testing.models.jpa.beanvalidation.Phone</class>
<validation-mode>CALLBACK</validation-mode>
</persistence-unit>
</persistence>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!--

Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved.
Copyright (c) 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
Expand All @@ -19,6 +19,7 @@
<class>org.eclipse.persistence.testing.models.jpa.beanvalidation.Employee</class>
<class>org.eclipse.persistence.testing.models.jpa.beanvalidation.Project</class>
<class>org.eclipse.persistence.testing.models.jpa.beanvalidation.Address</class>
<class>org.eclipse.persistence.testing.models.jpa.beanvalidation.Phone</class>
<validation-mode>CALLBACK</validation-mode>
<properties>
<property name="eclipselink.target-server" value="@server-platform@"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009, 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009, 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
Expand Down Expand Up @@ -50,6 +50,10 @@ public class Employee {
@Valid
@Embedded
private Address adress;

@Valid
@Embedded
private Phone phone;

// ===========================================================
// getters and setters for the state fields
Expand Down Expand Up @@ -105,4 +109,11 @@ void m1() {
return "Employee {Id:" + id + " name:" + name + "}";
}

public Phone getPhone() {
return phone;
}

public void setPhone(Phone phone) {
this.phone = phone;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright (c) 2009, 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
* http://www.eclipse.org/legal/epl-2.0,
* or the Eclipse Distribution License v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/

// Contributors:

package org.eclipse.persistence.testing.models.jpa.beanvalidation;

public interface GermanPhone {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2009, 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
* http://www.eclipse.org/legal/epl-2.0,
* or the Eclipse Distribution License v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/

// Contributors:

package org.eclipse.persistence.testing.models.jpa.beanvalidation;

import javax.persistence.Embeddable;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;

@Embeddable
public class Phone {
@Pattern(regexp = "^\\+1 \\([0-9]{3}\\) [0-9]{3}-[0-9]{4}$", groups = { USPhone.class })
@Pattern(regexp = "^\\+49 \\([1-9]\\d{1,4}\\) \\d{3,8}-\\d{4}$", groups = { GermanPhone.class })
String phone;

public Phone() {}

public Phone(String phone) {
this.phone = phone;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright (c) 2009, 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
* http://www.eclipse.org/legal/epl-2.0,
* or the Eclipse Distribution License v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/

// Contributors:

package org.eclipse.persistence.testing.models.jpa.beanvalidation;

public interface USPhone {

}
Loading
Loading