EclipseLink: How to enable Bean Validation without JEE/CDI? (aka enabling in SE)

119 views Asked by At

We have a test extension that creates an EntityManager for our tests:

Map<String, String> properties = new HashMap<String, String>(); properties.put(PersistenceUnitProperties.JDBC_DRIVER, DRIVER_NAME); properties.put(PersistenceUnitProperties.JDBC_URL, createUrl(testInstance)); properties.put(PersistenceUnitProperties.JDBC_USER, DB_USER); properties.put(PersistenceUnitProperties.COORDINATION_PROTOCOL, null); emf = Persistence.createEntityManagerFactory(PU_NAME, properties); ... EntityManager em = emf.createEntityManager();

We noticed though that there isn't a BeanValidator firing on pre-persist or pre-update, even though our other validators are firing just fine. This makes sense, in a JEE container, the Bean Validation library is provided by the container itself.

Is it possible to have have something have EclipseLink call out to something like OpenWebBeans if we include it on the test classpath?

1

There are 1 answers

0
Jonathan S. Fisher On BEST ANSWER

This was as simple as adding this to our pom:

    <dependency>
        <groupId>org.apache.bval</groupId>
        <artifactId>bval-jsr</artifactId>
        <version>1.1.2</version>
        <scope>test</scope>
    </dependency>