开发者

How to handle exceptions raised by @Transactional annotation

How to handle exceptions raised by @Transactional annotation. In a case where TransactionSystemException includes a ConstraintViolationException due to not null constraint violation for an ent开发者_Go百科ity annotated with @Entity.

I am using Hibernate.


This particular exception should be handled by fixing the bug it reveals: the code is trying to create an object with a null property, and this property may not be null. It means that the code forgot to populate this property, or didn't handle the validation of the user-entered data correctly.


I have left thinking about "having a need of exception finally!" here is another way to test and validate the constraints and constraint violations. Validator validator = Validation.buildDefaultValidatorFactory().getValidator(); Set> constraintViolations = validator.validateValue(Course.class, "name", null); assertEquals(1, constraintViolations.size()); –

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜