Skip to content
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

Proposal: Have to the ability to dynamically set the Validation Group for pre-persist during transaction #1806

Open
exabrial opened this issue Feb 5, 2023 · 2 comments

Comments

@exabrial
Copy link

exabrial commented Feb 5, 2023

One weakness of the JPA Specification is that you cannot (to my knowledge) specify a validation group to evaluate during a persist call.

Example: This does not work:

em.setProperty(PersistenceUnitProperties.VALIDATION_GROUP_PRE_PERSIST, SomeValidationGroup.class.toString());
em.persist(entity);

Looking at BeanValidationListener.java however, this seems like it'd be trivial to implement.

Existing code:

    @Override
    public void prePersist (DescriptorEvent event) {
        validateOnCallbackEvent(event, "prePersist", groupPrePersit);
    }

Proposal:

    @Override
    public void prePersist (DescriptorEvent event) {
        Class<?>[] overrideGroup = event.getSession().getParent().getProperties.get("eclipselink.validation.override.pre-persist");
        if (overrideGroup != null){
            validateOnCallbackEvent(event, "prePersist", overrideGroup);
        } else {
            validateOnCallbackEvent(event, "prePersist", groupPrePersit);
        }
    }

If we put together a patch, does anyone have any concerns about this? What we would need to submit for tests, docs, etc? We're still using 2.7.x series, but we'd try to patch all of the active development versions (what are they?)

Thank you!

@exabrial
Copy link
Author

Anyone? :) we're still happy to work on this. Just wondering what the chances of a merge are before we do the work.

As always, thank you EclipseLink team for your hard work.

@exabrial
Copy link
Author

Hello EclipseLink team, I just wanted to say thank you for all your work. We love EclipseLink and appreciate all the leadership on the project.

I know what we're requesting is outside the spec of JPA, and I just want to make sure that's ok. I think a lot of users would fine this quite useful. I hope to implement it in a similar vein to how MULTITENANT_PROPERTY_DEFAULT works which is also outside the JPA spec, but works quite nicely and is a very useful feature.

Thank you again

exabrial added a commit to exabrial/eclipselink that referenced this issue Nov 28, 2023
exabrial added a commit to exabrial/eclipselink that referenced this issue Aug 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant