Hi, i'm new on Java and i am new here too, i don't know if this is the right way or if i need to add a new thread, but the subject of my question is the same.
I was working in a small application using RESTful web services (using annotations) and doing all the persistence stuff by myself, now the application has grown and i want to use JPA (Hibernate) but i can not get it to work...
I'm using NetBeans IDE 6.1, i first tried the simple way, just by creating the Entity Classes with the wizard and then creating the RESTful web services based on those entities also using also the wizards, ...but when i run the services i have the following error:
javax.servlet.ServletException: com.sun.jersey.api.container.ContainerException: java.lang.NoClassDefFoundError: Could not initialize class org.hibernate.ejb.Ejb3Configuration
Then i tried to use Hibernate without annotations (mapping with hbm files) and the test works but when i put the same code inside a Web Service and i call it from the browser i have this error:
java.lang.NoClassDefFoundError: Could not initialize class de.javalog.beans.HibernateUtil
services.TestService.get(TestService.java:36)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
com.sun.jersey.impl.model.method.dispatch.EntityParamDispatchProvider$TypeOutInvoker._dispatch(EntityParamDispatchProvider.java:131)
com.sun.jersey.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:81)
com.sun.jersey.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:133)
com.sun.jersey.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:71)
com.sun.jersey.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:111)
com.sun.jersey.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:64)
com.sun.jersey.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:669)
com.sun.jersey.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:631)
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:291)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
This is the source code of my HibernateUtil class:
import org.hibernate.cfg.Configuration;
import org.hibernate.SessionFactory;
public class HibernateUtil {
private static final SessionFactory sessionFactory;
static {
try {
sessionFactory = new Configuration().configure("hibernate.cfg.xml").buildSessionFactory();
} catch (Throwable ex) {
// Log the exception.
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}
Any suggestion?
[Message sent by forum member 'zeven' (zeven)]
http://forums.java.net/jive/thread.jspa?messageID=297850