* because in Mod4j 1.0.0 validators are not being added to a persistent
* object when loaded by Hibernate.
*/
@Test
public void testValidateAfterRetrieve() {
Customer customer = new Customer("Johannes", "Vermeer", date(), 222);
try {
customer.setNumberOfEars(1);
fail("Expected BusinessRuleException");
} catch (BusinessRuleException e) {
/**
* This method throws an exception because a validation is
* triggered. Validators are added in the minimal constructor
* invoked above.
*/
}
try {
customer.setUsername("12");
fail("Expected BusinessRuleException");
} catch (BusinessRuleException e) {
}
Long id = customerDao.add(customer);
flush();
clear();
customer = customerDao.retrieve(id);
/*
* Now the object is instantiated by Hibernate. Hibernate does not use
* the minimal constructor, but the default no-arg constructor. The
* validators must still be added, causing the exception to be thrown.
*/
try {
customer.setNumberOfEars(1);
fail("Expected BusinessRuleException");
} catch (BusinessRuleException e) {
}
}