0

I am trying to use hibernate in my appllication but, it is throwing a exception. Following is the stacktrace when I am trying to run it. When I try to connect in simple java it works fine.

java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "createClassLoader")
java.security.AccessControlContext.checkPermission(AccessControlContext.java:372)
java.security.AccessController.checkPermission(AccessController.java:559)
java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
java.lang.SecurityManager.checkCreateClassLoader(SecurityManager.java:611)
java.lang.ClassLoader.checkCreateClassLoader(ClassLoader.java:275)
java.lang.ClassLoader.<init>(ClassLoader.java:317)
org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl$AggregatedClassLoader.<init>(ClassLoaderServiceImpl.java:179)
org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl$AggregatedClassLoader.<init>(ClassLoaderServiceImpl.java:175)
org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.<init>(ClassLoaderServiceImpl.java:109)
org.hibernate.boot.registry.BootstrapServiceRegistryBuilder.build(BootstrapServiceRegistryBuilder.java:241)
org.hibernate.boot.registry.StandardServiceRegistryBuilder.<init>(StandardServiceRegistryBuilder.java:73)
   org.geeksngeeks.database.ConnectionManager.init(ConnectionManager.java:43)
org.geeksngeeks.config.InitConfig.triggerAppStartup(InitConfig.java:252)

Following is my code to connect to DB.

Properties props = new Properties();

try {
  ResourceBundle rb = ResourceBundle.getBundle("hibernate");
  for (final Object name : rb.keySet()) {
    final String sName = String.valueOf(name);
    props.setProperty(sName.toLowerCase(), rb.getString(sName));
  }
} catch (Exception ex) {
  props.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
  props.setProperty("hibernate.connection.driver_class", "com.mysql.jdbc.Driver");
  props.setProperty("hibernate.connection.url", "jdbc:mysql://mysql-dev-01.cloud.wso2.com:3306/my_db_name");
  props.setProperty("hibernate.connection.username", "user");
  props.setProperty("hibernate.connection.password", "paswd");
  props.setProperty("hibernate.hbm2ddl.auto", "update");
}
Configuration configuration = new Configuration();
configuration.configure(new URL(Config.getWebserver() + "hibernate.cfg.xml"));
//configuration.setProperties(props);
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().
    applySettings(configuration.getProperties()).build();

factory = configuration.buildSessionFactory(serviceRegistry);
Rohit Rehan
  • 568
  • 1
  • 4
  • 18

2 Answers2

0

According to this line:

java.lang.SecurityManager.checkCreateClassLoader(SecurityManager.java:611)

Your Java process has some Security-policies enabled. This one at least for sure:

permission java.lang.RuntimePermission "createClassLoader";

You need to disable this setting, otherwise your application will not be allowed to instantiate a new classloader, and it apparently needs that.

Gergely Bacso
  • 14,243
  • 2
  • 44
  • 64
0

Indeed, Security Manager is preventing the load. WSO2 Cloud should be able to enable Hibernate for you if you submit the request: just log into WSO2 App Cloud and click Support / Contact Us to send the request.

DSotnikov
  • 634
  • 3
  • 10