Reputation: 3084
I am trying to incorporate Hibernate v4 in my Dynamic Web project in eclipse. I am using Maven for dependencies. I wrote all the code and created entity classes and mapping xml files but on building project I get this error
The project was not built since its build path is incomplete. Cannot find the class file for javax.naming.Referenceable.
Fix the build path then try building this project MyProject
I wrote HibernateUtil class as this:
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
public class HibernateUtil {
private static SessionFactory sessionFactory = buildSessionFactory();
private static SessionFactory buildSessionFactory() {
try {
if (sessionFactory == null) {
Configuration configuration = new Configuration()
.configure(HibernateUtil.class
.getResource("/hibernate.cfg.xml"));
StandardServiceRegistryBuilder serviceRegistryBuilder = new StandardServiceRegistryBuilder();
serviceRegistryBuilder.applySettings(configuration
.getProperties());
ServiceRegistry serviceRegistry = serviceRegistryBuilder
.build();
sessionFactory = configuration
.buildSessionFactory(serviceRegistry);
}
return sessionFactory;
} catch (Throwable ex) {
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
public static void shutdown() {
getSessionFactory().close();
}
}
EDIT: I get this error on getSessionFactory method call in shutdown method. Anyone knows what can be problem?
Upvotes: 0
Views: 277
Reputation: 1023
The problem lies in you trying to use the Referenceable interface class somewhere and that class is not available on the build path. Like it says, you must fix the build path. Do this by providing the package that has javax.naming.Referenceable.
What I find strange is why rewrite the HibernateUtil class? This is probably not something you want to do here. And I see no explanation as to why you would write your own.
I would recommend forget the HibernateUtil class and start using the Hibernate framework in its entirety.
Upvotes: 1