Does Hibernate 3.6.6 Final and Glassfish 3.1 have incompatibilities in bean-validator.jar and validation-api-1.0.0.GA.jar ?
Following scenario:
I start the web application in Eclipse 3.6 with the command "Debug As -> Debug on Server" and i choose the Glassfish Server as Server to run the application with.
When Hibernate tries to build the SessionFactory it throws the Exception
org.hibernate.validator.HibernateValidator cannot be cast to javax.validation.spi.ValidationProvider
The file bean-validator.jar coming with Glassfish Server contains a package with "Hibernate Validator 4.1.0.Final".
The validation-api-1.0.0.GA.jar is put in directory "glassfish3\glassfish\domains\domain1\lib\ext" and is used by "Hibernate Validator 4.1.0.Final".
When i delete the validation-api-1.0.0.GA.jar from directory "glassfish3\glassfish\domains\domain1\lib\ext" i get the exception
java.lang.ClassNotFoundException: javax.validation.Validation
So there must be a dependency between the Hibernate Validator 4.1.0.Final in bean-validator.jar and the validation-api-1.0.0.GA.jar .
But why does Hibernate can't build the SessionFactory and throws the Exception ?
Code:
public class HibernateUtil {
private static final SessionFactory sessionFactory = buildSessionFactory();
private static SessionFactory buildSessionFactory() {
SessionFactory sessionFactory = null;
try{
sessionFactory = getInitializedConfiguration().buildSessionFactory(); <--- when these method is called the exception is thrown
}catch(HibernateException e) {
System.out.println("");
e.printStackTrace();
}
return sessionFactory;
}
//============================ public accessors
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
public static Session getCurrentSession() {
return sessionFactory.getCurrentSession();
}
//============================ private methods
private static Configuration getInitializedConfiguration() throws HibernateException {
Configuration configuration = null;
configuration = new Configuration().configure("/hibernate.cfg.xml");
return configuration;
}
}