Results 1 to 8 of 8
Like Tree1Likes
  • 1 Post By gimbal2

Thread: Making a simple servlet with hibernate query

  1. #1
    smacker is offline Member
    Join Date
    Jan 2011
    Posts
    46
    Rep Power
    0

    Default Making a simple servlet with hibernate query

    hello all , trying to make a servlet that will print a simple query with hibernate, when i do so it fails with this error:
    Java Code:
    SEVERE: Allocate exception for servlet ShowAccuracy
    java.lang.ClassNotFoundException: org.hibernate.service.ServiceRegistry
    	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
    	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
    	at java.lang.Class.getDeclaredConstructors0(Native Method)
    	at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
    	at java.lang.Class.getConstructor0(Unknown Source)
    	at java.lang.Class.newInstance(Unknown Source)
    	at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1149)
    	at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:827)
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:129)
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
    	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
    	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
    	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    	at java.lang.Thread.run(Unknown Source)
    it fails on the first line of code :
    Java Code:
    public void init(ServletConfig config) throws ServletException {
    		// TODO Auto-generated method stub
    		Configuration conf = new Configuration();
    		conf.configure();
    		StandardServiceRegistry sr=new StandardServiceRegistryBuilder().applySettings(conf.getProperties()).build();
    		factory=(SessionFactory) conf.buildSessionFactory(sr);
    	}
    the Configuration line , if i delete all the hibernate lines it work
    not sure if it's the right forum but it is a servlet so..
    any ideas on why it fails ?
    thanks to all the helpers !

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,049
    Rep Power
    6

    Default Re: Making a simple servlet with hibernate query

    So did you add the hibernate jars to the WEB-INF/lib of your web application?

    A ClassNotFound error is something very basic you know, you should be able to recognize them and be able to solve them if you do such advanced things as web development and Hibernate. Perhaps you may need to take a few steps back and practice more with regular Java programming. For example: try to get a simple client side application working with Hibernate, so no web environment is involved. That will teach you how to manage classpaths and work with libraries. The Hibernate documentation should be able to tell you how.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,036
    Rep Power
    20

    Default Re: Making a simple servlet with hibernate query

    Are the Hibernate jars in the WEB-INF/lib directory?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  4. #4
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,049
    Rep Power
    6

    Default Re: Making a simple servlet with hibernate query

    Quote Originally Posted by Tolls View Post
    Are the Hibernate jars in the WEB-INF/lib directory?
    *throws ninja stars at Tolls*
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,036
    Rep Power
    20

    Default Re: Making a simple servlet with hibernate query

    Quote Originally Posted by gimbal2 View Post
    *throws ninja stars at Tolls*
    Ow!
    OW!!

    Stop that!
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  6. #6
    smacker is offline Member
    Join Date
    Jan 2011
    Posts
    46
    Rep Power
    0

    Default Re: Making a simple servlet with hibernate query

    now now , no need to throw ninja stars

    well i already add the jars but not to the web-inf\lib , i added them through add external jar to the Libraries , already used the hibernate , but not on the servlet ,
    on some other class i did,
    didn't know i needed to put them directly there , Thanks !

    on another note , the dangers of ninja stars :
    Making a simple servlet with hibernate query-ninja-star-butters.png

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,036
    Rep Power
    20

    Default Re: Making a simple servlet with hibernate query

    Depends on how it is being deployed to the server.
    It should be part of the build.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  8. #8
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,049
    Rep Power
    6

    Default Re: Making a simple servlet with hibernate query

    Quote Originally Posted by smacker View Post
    didn't know i needed to put them directly there , Thanks !
    Just to warn you: there are about a million other things you also don't know then as this is the basics of the basics of packaging a web application. I suggest you study into how you properly do that. And when you know how to do that, you can also properly use tools that do it for you.
    smacker likes this.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Database Query using Hibernate
    By javababy in forum Web Frameworks
    Replies: 0
    Last Post: 08-02-2011, 11:54 AM
  2. hibernate distinct query
    By GlWy in forum JDBC
    Replies: 2
    Last Post: 04-07-2011, 06:59 PM
  3. Hibernate Join Query - Should be easy
    By ajt111 in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 10-29-2009, 05:48 PM
  4. Help query with hibernate
    By wonderbiker in forum JDBC
    Replies: 0
    Last Post: 04-14-2009, 11:12 AM
  5. Hibernate sql query
    By taicode in forum JDBC
    Replies: 0
    Last Post: 03-25-2008, 04:17 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •