hibernate-validatior-cdi: Why is the ConstraintValidator not a managed instance in the weld-se container?

72 views Asked by At

In our project we are testing jpa database access with the weld-junit5 framework. The EntityManager is injected into the test class. The entity to be saved is annotated with a custom validator.

https://github.com/duschata/testingIssues/blob/ce5c6d0bd8b778e75d69246f39d78da16305caaa/src/main/java/com/foo/bar/entity/TestEntity.java#L21-L22

The problem is that the custom validator itself needs an instance, which in this case is not injected.

https://github.com/duschata/testingIssues/blob/ce5c6d0bd8b778e75d69246f39d78da16305caaa/src/main/java/com/foo/bar/validation/MyValidator.java#L10-L28

A nullpointer exception is thrown here because myDao was not instantiated.

For more clarity you can browse throw this essential project on github (branch validation)

https://github.com/duschata/testingIssues/tree/validation

Kind regards Tom

0

There are 0 answers