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

constraint mappings specified in META-INF/validation.xml aren't applied #5531

Open
rpdeadly opened this issue Nov 16, 2019 · 5 comments · May be fixed by #42292
Open

constraint mappings specified in META-INF/validation.xml aren't applied #5531

rpdeadly opened this issue Nov 16, 2019 · 5 comments · May be fixed by #42292
Assignees
Labels

Comments

@rpdeadly
Copy link

rpdeadly commented Nov 16, 2019

Hibernate's Validator implementation fails to catch any violation. I've got all of my validation rules specified in an XML ( because I do not have access to the source code ).


META-INF/validation.xml

<validation-config
        xmlns="http://xmlns.jcp.org/xml/ns/validation/configuration"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/validation/configuration https://beanvalidation.org/xml/ns/validation/validation-configuration-2.0.xsd"
        version="2.0">
    <constraint-mapping >
    	META-INF/validation/organization.xml
    </constraint-mapping>
</validation-config>


META-INF/validation/organization.xml

<constraint-mappings
	xmlns="http://xmlns.jcp.org/xml/ns/validation/mapping"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/validation/mapping
            http://xmlns.jcp.org/xml/ns/validation/mapping/validation-mapping-2.0.xsd"
	version="2.0">
	<bean class="demo.Organization"
		ignore-annotations="true">
		<field name="owner">
			<constraint
				annotation="javax.validation.constraints.NotNull">
				<message>Org owner must be specifed</message>
			</constraint>
		</field>
	</bean>
</constraint-mappings>  

In my service I'm trying to validate the object

@Inject
Validator validator;
...
Set<ConstraintViolation> violations = validator.validate( myOrg );
if( ! violations.isEmpty() ) return false;

The violation set is always empty. I've tried my configuration using a standalone implementation
of hibernate-validator and it works.

@rpdeadly rpdeadly added the kind/bug Something isn't working label Nov 16, 2019
@jaikiran jaikiran added the area/hibernate-validator Hibernate Validator label Nov 17, 2019
@geoand
Copy link
Contributor

geoand commented Nov 17, 2019

I am not sure that violation.xml is even supported.
@gsmet can of course shine all the necessary light here

@machi1990
Copy link
Member

I can see that the file it is hot reloaded 45f875b#diff-b325242f07b81465b410fd3c1e40914aL78 but we are not trying to parse it anywhere. Let's wait for @gsmet to give his thoughts.

@gsmet
Copy link
Member

gsmet commented Nov 17, 2019

Right now, we only support annotations in Quarkus. It should probably be documented if it's not already.

I'm still unsure if we should implement more of the logic in Quarkus or if we should move all this discovery to HV somehow.

@rpdeadly
Copy link
Author

rpdeadly commented Nov 18, 2019

I found a partial work around. The rules specified in validation.xml are applied if i create a dummy class that extends the class I'm trying to validate. But validation cascading doesn't work.

	<field name="owner">
		<valid></valid>
		<convert-group
				from="demo.NewOrgCheck"
				to="demo.NewOwnerCheck" />
                    <constraint
				annotation="javax.validation.constraints.NotNull">
				<message>Org owner must be specifed</message>
			</constraint>
	</field>

The fields within the owner class aren't validated.

@marko-bekhta
Copy link
Contributor

A corresponding Hibernate Validator issue: https://hibernate.atlassian.net/browse/HV-2031

@marko-bekhta marko-bekhta linked a pull request Sep 5, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants