I'm (very) new to JSR303 validation and hibernate validation, basically I don't really know quite what is going on yet :-) Quite excited about the possibilites though being an Eiffel fan from many years ago.
I have a dto class like so
Code:
public final class Identifier implements Serializable
{
private final String namespace;
@NotNull
@Size(min = 1)
private final String name;
public Identifier(String namespace,
String name)
{
this.namespace = namespace;
this.name = name;
}
public String getNamespace()
{
return namespace;
}
public String getName()
{
return name;
}
}
and I use this in a method on a stateless session bean running in jboss 7.1
Code:
@Stateless @LocalBean
@TransactionManagement(TransactionManagementType.CONTAINER)
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class PatientRecordOperations
{
...
public Identifier addPatient(@NotNull @Valid
Identifier patientId)
{
...
}
...
}
I was expecting that the patientId parameter would be checked if it is null and also that the name attribute inside the patientId object would also be checked for null and for a string length of greater than 0.
None of the checking seems to be occurring. I must be missing something but I cannot work out what.
JBoss 7.1.1 has hibernate validator 4.2.0.Final included so that is what should be used. The ejb configuration is as shown, there is no XML configuration included with its deployment. I am calling the bean method from an arquillian test case that is also running within the application server so the ejb invocation is a local call but it should be going through all the interceptors (the stack traces I see confirm this).
Any ideas what to try next?
thanks.
P.S. I have tried calling a validator directly using this in the class
Code:
@Resource
private Validator validator;
and this in the method
Code:
Set<ConstraintViolation<Identifier>> cvs = validator.validate(patientId);
if (!cvs.isEmpty()) throw new Cpf4Exception("bad args");
and the exception is thrown as expected when the name attribute of patientId is an empty string or null.