开发者

Spring MVC, Hibernate 3 and @Valid Problem

开发者 https://www.devze.com 2023-02-10 20:57 出处:网络
I have a Spring MVC with JDBC that uses @Valid annotations and it all works very nicely, including the validation.

I have a Spring MVC with JDBC that uses @Valid annotations and it all works very nicely, including the validation.

Now I have created a similar webapp that uses Hibernate (instead of JDBC) and it also works nicely so far.

I decided to 'bolt in' validation before continuing with more domains etc.

So I added @Valid to the save process in the Controller as so:

@RequestMapping(value = "/productgroup/save", method = RequestMethod.POST)
public String updateProductGroup(**@Valid** ProductGroup productGroup, BindingResult bindingResult) 

That is t开发者_如何学Che only change that I make and now it crashes with:

SEVERE: Servlet.service() for servlet appServlet threw exception
java.lang.NoSuchMethodError: javax.persistence.Persistence.getPersistenceUtil()Ljavax/persistence/PersistenceUtil;
    at org.hibernate.validator.engine.resolver.JPATraversableResolver.isReachable(JPATraversableResolver.java:33)
    at org.hibernate.validator.engine.resolver.DefaultTraversableResolver.isReachable(DefaultTraversableResolver.java:112)
    at org.hibernate.validator.engine.resolver.SingleThreadCachedTraversableResolver.isReachable(SingleThreadCachedTraversableResolver.java:47)
    at org.hibernate.validator.engine.ValidatorImpl.isValidationRequired(ValidatorImpl.java:764)
    at org.hibernate.validator.engine.ValidatorImpl.validateConstraint(ValidatorImpl.java:331)
    at org.hibernate.validator.engine.ValidatorImpl.validateConstraintsForRedefinedDefaultGroup(ValidatorImpl.java:278)
    at org.hibernate.validator.engine.ValidatorImpl.validateConstraintsForCurrentGroup(ValidatorImpl.java:260)
    at org.hibernate.validator.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:213)
    at org.hibernate.validator.engine.ValidatorImpl.validate(ValidatorImpl.java:119)
    at org.springframework.validation.beanvalidation.SpringValidatorAdapter.validate(SpringValidatorAdapter.java:86)

I am using: org.hibernate hibernate-validator 4.0.2.GA jar javax.validation validation-api 1.0.0.GA

I have tried @NotEmpty on both the ProductGroup's productGroupName field and its Getter.

Any ideas?

I really never expected any problems here as I had no problems getting validation to work in my JDBC version...


Hibernate Validator has an optional dependency on JPA, but when JPA is present in the classpath, Hibernate Validator 4 requires it to be JPA 2.0. In your case you have JPA 1.0 in the classpath.

In other words, Hibernate Validator 4 is compatible with Hibernate 3.5 or above. For older version of Hibernate see Hibernate Compatibility Matrix.

0

精彩评论

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