سؤال

I am using JSF 2 ,myfaces, hibernate-validator-4.1.0.Final.jar.

I use hibernate-validator for validating values entered in form.

public class Client {
   @Persistent
   @Pattern(regexp = "|.+@.+\\.[a-z]+", message = "Email format is invalid.")
   private String email;
   //getter
}

I am developing bulk-upload module ,where i parse csv data and create database records.

...
try{
  Client cl=new Client();
  cl.setEmail("from_csv_data");
}catch( //validation failed

How do i reuse the same validator here?



Set> constraintViolations = validator.validate(nc);
throws this exception

SEVERE: Received 'java.lang.NoSuchMethodError' when invoking action listener '#{clientBean.bulkUpload}' for component 'j_idt86'

Jan 28, 2011 8:35:39 AM javax.faces.event.MethodExpressionActionListener processAction
SEVERE: java.lang.NoSuchMethodError: javax.persistence.Persistence.getPersistenceUtil()Ljavax/persistence/PersistenceUtil; at org.hibernate.validator.engine.resolver.JPATraversableResolver.isReachable(JPATraversableResolver.java:62)

I tried this solution link
I have hibernate-jpa-2.0-api-1.0.0.Final.jar,hibernate-validator-4.1.0.Final.jar
Do I need any other jar to make this work?

هل كانت مفيدة؟

المحلول

You can invoke the validator manually with something like:

ValidatorFactory factory = Validation.buildDefaultValidatorFactory();

Validator validator = factory.getValidator();

Client client = new Client();

Set<ConstraintViolation<Client>> constraintViolations = validator.validate(client);

نصائح أخرى

You most likely have another incomplete JPA 2 jar file on the classpath. Unfortunately, some incomplete versions of this jar got released at some stage (TopLink for example). Check your classpath for any jar containing JPA classes. See also https://forum.hibernate.org/viewtopic.php?f=9&t=999855

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top