Using hibernate validator JodaTime bean validation restrictions in JBoss

We have an enterprise application that uses the Joda DateTime library. The application is deployed to the JBoss 7.2.0 Alpha1 container. Some classes in our domain model have @Past annotations in DateTime fields. To verify these constraints, we would like to use the constraint validators provided by the hibernate-validator. Therefore, we added the dependency "org.hibernate.validator" to the MANIFEST.MF file of our ear file. We are using version 2.0 of the Joda library. Therefore, we packed the joda-time-2.0.jar file in our ear. We do not use version 1.6.2, which is available as a JBoss 7 module

When checking an object with a DateTime field, the following exception:

10:51:41,140 ERROR [org.acme.GlobalExceptionHandler] (EJB default - 10) Exception caught by global exception handler: javax.validation.UnexpectedTypeException: No validator could be found for type: org.joda.time.DateTime
at org.hibernate.validator.engine.ConstraintTree.verifyResolveWasUnique(ConstraintTree.java:383) [hibernate-validator-4.2.0.Final.jar:4.2.0.Final]
at org.hibernate.validator.engine.ConstraintTree.findMatchingValidatorClass(ConstraintTree.java:364) [hibernate-validator-4.2.0.Final.jar:4.2.0.Final]
at org.hibernate.validator.engine.ConstraintTree.getInitializedValidator(ConstraintTree.java:313) [hibernate-validator-4.2.0.Final.jar:4.2.0.Final]
at org.hibernate.validator.engine.ConstraintTree.validateConstraints(ConstraintTree.java:144) [hibernate-validator-4.2.0.Final.jar:4.2.0.Final]
at org.hibernate.validator.engine.ConstraintTree.validateConstraints(ConstraintTree.java:117) [hibernate-validator-4.2.0.Final.jar:4.2.0.Final]
at org.hibernate.validator.metadata.MetaConstraint.validateConstraint(MetaConstraint.java:84) [hibernate-validator-4.2.0.Final.jar:4.2.0.Final]
at org.hibernate.validator.engine.ValidatorImpl.validateConstraint(ValidatorImpl.java:452) [hibernate-validator-4.2.0.Final.jar:4.2.0.Final]

After some debugging, we found that calling “TypeUtils.isAssignable (validatorType, type)” in “ConstraintTree.findSuitableValidatorTypes” fails because the available validator types are taken from the Joda library, which was sent from JBoss instead of the Joda library, which is packaged in our ear file.

I think we are doing something wrong with regard to loading classes. Can someone give me a hint?

+5
source share
2 answers

Have you tried adding jboss-deployment-structure.xml to your ear file? Thus, you should be able to exclude the Joda time module:

<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
    <deployment>
        <exclusions>
            <module name="org.joda.time"/>
        </exclusions>
    </deployment>
</jboss-deployment-structure>

See also https://docs.jboss.org/author/display/AS7/Class+Loading+in+AS7

+3
source

Hardy, jboss-deployment-structure.xml WEB-INF , :

<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
    <deployment>
        <exclusions>
            <module name="org.hibernate.validator" />
        </exclusions>
    </deployment>
</jboss-deployment-structure>

org.joda.time org.hibernate.validator. , .

+2

All Articles