-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Creating Configuration object inside doGet method of servlet
PostPosted: Thu Sep 29, 2016 2:34 am 
Newbie

Joined: Thu Sep 29, 2016 2:26 am
Posts: 1
The sevlet code giving Exception 'java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "createClassLoader")'

Code:
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {

    String name=req.getParameter("name");
    String email=req.getParameter("email");
    int marks=Integer.parseInt(req.getParameter("marks"));

    Student st=new Student(0,name,email,marks);

    System.out.println("Inside get method before configuration object generation");
    Configuration cfg=new Configuration();
    System.out.println("After configuration initialization");
    cfg.configure("Resourses/hibernate.cfg.xml");
    System.out.println("after giving hibernate config file");
    sf=cfg.buildSessionFactory();

}



I am getting this error

Code:
Sep 25, 2016 8:56:41 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [Controller.StudentRegistrationServlet] in context with path [/StudentRegistration] threw exception
java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "createClassLoader")
    at java.security.AccessControlContext.checkPermission(AccessControlContext.java:457)
    at java.security.AccessController.checkPermission(AccessController.java:884)
    at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)



Creation of Configuration object inside servlet giving me this exception. Pls help.


Top
 Profile  
 
 Post subject: Re: Creating Configuration object inside doGet method of servlet
PostPosted: Thu Sep 29, 2016 3:13 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
The SessionFactory is meant to be created once, when the web/application server bootstraps. This is because the SessionFactory is an expensive object which takes time to initialize.

You should never create a SessionFactory on every HTTP request. Instead, you should use the already created SessionFactory to spawn a new Session instance for every HTTP request.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.