To validate my entity beans I have created this validation method inside my bean
@PrePersist
@PreUpdate
public void validate(){
if (startTime.after(stopTime)) throw new ValidationException("Wrong order");
}
The ValidationException looks like this:
@ApplicationException(rollback = true)
public class ValidationException extends RuntimeException {
public ValidationException(String message) {
super(message);
}
}
If I try to create a bean with
try {
timeframefacade.create(timeframe);
} catch (Exception e) {
System.out.println(e.getMessage());
e.getMessage() returns "Wrong order", which is correct
try {
timeframefacade.edit(timeframe);
} catch (Exception e) {
System.out.println(e.getMessage());
it returns "Transaction aborted" which is an EJBException. How do I get the same result as above and avoid all the logging, which also occurs?
Call flush within your edit method to force the preupdate. Otherwise it occurs when the transaction is completing and the container must throw a transaction exception instead.