Announcement Announcement Module
No announcement yet.
Problem with Hibernate and Spring Web application Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem with Hibernate and Spring Web application

    Hello, I'm new to Spring and Hibernate.

    I have generated with Hibernate Tools a database access module. The generator generates the code of the DAOS and Hibernate Beans.

    When I test this module in a simple Java application all works fine, but when I test it in a Spring Web application I get a very strange error. Since my module is an independent jar it should access the database without regarding the circumstance of being executed in a simple Java application or a Web application. The code of my web application is:

      public class Controller implements ApplicationContextAware
       private ApplicationContext applicationContext;
       @RequestMapping(value = "/purchased/songs", method = RequestMethod.GET)
       public String home(Model model)
         ChargeTryDAOBase ctdb=new ChargeTryDAOBase();
         List <ChargeTry> data=ctdb.findByRemoteId("dsfsdfsdf8");
         model.addAttribute("result", "data" );
         return "home";
       public void setApplicationContext(ApplicationContext arg0) throws BeansException
         this.applicationContext = arg0;

    When running this code on Tomcat I get following error:

    org.springframework.web.util.NestedServletException: Handler processing
     nested exception is java.lang.NoSuchMethodError: 
    When I change some Hibernate dependencies I get following error:

    java.lang.IllegalStateException: Could not locate SessionFactory in JNDI
    When I test the above code in a simple Java application all works fine.

    Is this a spring-hibernate configuration problem?

    Is it possible to encapsulate all hibernate configuration in my hibernate.cfg.xml contained in my jar, not having to configure it in my upper Spring layer?

    My hibernate.cfg.xml file is:

            <property name="hibernate.bytecode.use_reflection_optimizer">false</property>
            <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
            <property name="hibernate.connection.password" />
            <property name="hibernate.connection.url">jdbc:mysql://database:3306/mydb</property>
            <property name="hibernate.connection.username">content</property>
            <property name="hibernate.current_session_context_class">thread</property>
            <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
            <property name="hibernate.format_sql">true</property>
            <property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
            <property name="hibernate.use_sql_comments">true</property>
    I think the problem is that I haven't enabled in my hibernate.cfg.xml the datasource for being used in Tomcat, but I'm not sure.

    Many thanks for your advice and help.