开发者

Entity persist register validation listener

I'm using JBoss 6 with Seam, and I have an entity I am trying to persist, User. I have extended org.jboss.seam.framework.EntityHome to provide a UserHome class and have overridden the persist() method. I have thoroughly annotated my entity class with javax.validation annotations. When I provide valid values for all the fields in my entity class, the object is persisted with no problems. When I violate one of the validation constraints, persistence fails as expected.

The issue I am having is with constraint violations during asynchronous persistence: hibernate does not tell me which constraint has been violate开发者_JAVA技巧d!

javax.validation.ConstraintViolationException: validation failed for classes [com.example.model.User] duringpersist time for groups [javax.validation.groups.Default, ]
at org.hibernate.cfg.beanvalidation.BeanValidationEventListener.validate(BeanValidationEventListener.java:132)
at org.hibernate.cfg.beanvalidation.BeanValidationEventListener.onPreInsert(BeanValidationEventListener.java:71)

If I force synchronous persistence by adding EntityManager.flush() to UserHome.persist(), then I can catch the ConstraintViolationException and output log statements containing the violated constraints.

My question: is it possible to register a listener with hibernate/jboss for the constraint violations? I think its a little lame that hibernate doesnt print the violations, but hopefully I can insert some code that will catch and log them for more info. Otherwise I have no idea what constraint was violated.

Thanks!

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜