Search code examples
javahibernategoogle-app-enginegwtinitial-context

Java + Hibernate4 + GWT + App Engine = InitialContext error


I try to develop a simple webapp using GWT + hibernate4 + Apache Tomcat. Now I have written my simple classes with GWT & hibernate (using the default App Engine server for the first time), but I get an error while sending data to server, whch arrises in class

public class HibernateUtil {
private static SessionFactory sessionFactory;
private static ServiceRegistry serviceRegistry;

static SessionFactory getSessionFactory() throws HibernateException {
    Configuration configuration = new Configuration();
    configuration.configure();
    serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();        
    sessionFactory = configuration.buildSessionFactory(serviceRegistry);
    return sessionFactory;
}

}

on the line sessionFactory = configuration.buildSessionFactory(serviceRegistry); Here is the stacktrace

    java.lang.NoClassDefFoundError: javax.naming.InitialContext is a restricted class. Please see the Google  App Engine developer's guide for more details.
    at com.google.appengine.tools.development.agent.runtime.Runtime.reject(Runtime.java:51)
at org.hibernate.service.jndi.internal.JndiServiceImpl.buildInitialContext(JndiServiceImpl.java:77)
at org.hibernate.service.jndi.internal.JndiServiceImpl.bind(JndiServiceImpl.java:107)
at org.hibernate.internal.SessionFactoryRegistry.addSessionFactory(SessionFactoryRegistry.java:79)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:440)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1737)
at ru.leti.alexeeva.server.HibernateUtil.getSessionFactory(HibernateUtil.java:17)

is there any way round?


Solution

  • What's happening is exactly what it says:

    "java.lang.NoClassDefFoundError: javax.naming.InitialContext is a restricted class. Please see the Google App Engine developer's guide for more details."

    Your code won't run like this, out of the box because of Google App Engine JRE whitelist. In other words, you can't use all Java classes and libraries that you can running a "standalone" Java app server like Tomcat.

    See precise list of which Java classes are allowed to be used in an application running on Google App Engine:

    http://code.google.com/appengine/docs/java/jrewhitelist.html