Results 1 to 9 of 9

Thread: No bean named 'sessionFactory' is defined

  1. #1
    Join Date
    Jan 2013
    Posts
    6

    Default No bean named 'sessionFactory' is defined

    Hi. Sorry for repeating the title of the thread, but all advices in other threads didn't help me. I'm making Spring MVC 3.1.1 + Hibernate app 3.5, netbeans 7.2.
    my entity class News.java:

    Code:
    package by.Entity;
    
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.Id;
    import javax.persistence.Table;
    
    /**
     *
     * @author Serge
     */
    @Entity
    @Table(name="News")
    public class News {
        
        private Long id;
        private String newsText;
        
        @Id
        @GeneratedValue
        @Column(name="ID")
        public Long getId(){
            return id;
        }
        
        public void setId(Long id){
            this.id = id;
        }
        
        @Column(name="NEWS_TEXT")
        public String getNewsId(){
            return newsText;
        }
        
        public void setNewsText(String newsText){
            this.newsText = newsText;
        }
    }
    it's my DAO interface NewsDAO.java:
    Code:
    package by.DAO;
    
    import by.Entity.News;
    import java.util.List;
    
    /**
     *
     * @author Serge
     */
    public interface NewsDAO{
        
        public void saveNews(News news);
        public void readNews(Long id);
        public void deleteNews(Long id);
        public List<News> listNews();
    }
    Interface implementation:
    Code:
    package by.DAO;
    
    import by.Entity.News;
    import java.util.List;
    import org.hibernate.SessionFactory;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Repository;
    
    /**
     *
     * @author Serge
     */
    @Repository
    public class NewsDAOImpl implements NewsDAO{
        
    //    @Autowired
        private SessionFactory sessionFactory;
            
        @Override
        public void saveNews(News news) {
           sessionFactory.getCurrentSession().save(news);
        }
    
        @Override
        public void readNews(Long id) {
            sessionFactory.getCurrentSession().load(News.class, id);
        }
    
        @Override
        public void deleteNews(Long id) {
            News news = (News) sessionFactory.getCurrentSession().load(News.class, id);
            if (null != news){
                sessionFactory.getCurrentSession().delete(news);
            }
        }
    
        @Override
        public List<News> listNews() {
            return sessionFactory.getCurrentSession().createQuery("from News")
                .list();
        }
        
    }
    Here is the service flow. NewsService.java:
    Code:
    package by.service;
    
    import by.Entity.News;
    import java.util.List;
    
    /**
     *
     * @author Serge
     */
    public interface NewsService {
        
        public void saveNews(News news);
        public void readNews(Long id);
        public void deleteNews(Long id);
        public List<News> listNews();
                
    }
    NewsServiceImpl.java:
    Code:
    package by.service;
    
    import by.DAO.NewsDAO;
    import by.Entity.News;
    import java.util.List;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;
    import org.springframework.transaction.annotation.Transactional;
    
    /**
     *
     * @author Serge
     */
    @Service
    public class NewsServiceImpl implements NewsService{
        
        @Autowired
        private NewsDAO newsDAO;
    
        @Transactional
        @Override
        public void saveNews(News news) {
            newsDAO.saveNews(news);
        }
        
        @Transactional
        @Override
        public void readNews(Long id) {
            newsDAO.readNews(id);
        }
    
        @Transactional
        @Override
        public void deleteNews(Long id) {
            newsDAO.deleteNews(id);
        }
    
        @Transactional
        @Override
        public List<News> listNews() {
            return newsDAO.listNews();
        }
        
    }
    My controller:
    Code:
    package by.controllers;
    
    /**
     *
     * @author Serge
     */
    import by.Entity.News;
    import by.service.NewsService;
    import java.util.Map;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    
    @Controller
    public class PagesController {
        
        @Autowired
        private NewsService newsService;
        
        @RequestMapping("/main")
        public String goHome(Map<String, Object> map){
            map.put("news", new News());
            map.put("newsList", newsService.listNews());
            return "main";
        }
        
        @RequestMapping("/news")
        public String goToNews(){
            return "news";
        }
        
        @RequestMapping("/games")
        public String goToGames(){
            return "games";
        }
        
        @RequestMapping("/video")
        public String goToVideo(){
            return "video";
        }
        
        @RequestMapping("/forum")
        public String goToForum(){
            return "forum";
        }
    }
    Next are my xml files. I use web.xml obviously and dispatcher-servlet.xml only. ApplicationContext.xml is empty.

    web.xml:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
    
        <listener>
            <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>
      
        <servlet>
            <servlet-name>dispatcher</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
            <init-param>
                <param-name>contextConfigLocation</param-name>
                <param-value>/WEB-INF/dispatcher-servlet.xml</param-value>
            </init-param>
            <load-on-startup>1</load-on-startup>
        </servlet>
        <servlet-mapping>
            <servlet-name>dispatcher</servlet-name>
            <url-pattern>/</url-pattern>
        </servlet-mapping>
        
        <session-config>
            <session-timeout>
                30
            </session-timeout>
        </session-config>
        
        <welcome-file-list>
            <welcome-file>redirect.jsp</welcome-file>
        </welcome-file-list>
        
    <!--     TransactionFilterException -->
    <!--    <filter>
            <filter-name>hibernateFilter</filter-name>
            <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
            <init-param>
                    <param-name>singleSession</param-name>
                    <param-value>true</param-value>
            </init-param>
        </filter>
    
        <filter-mapping>
            <filter-name>hibernateFilter</filter-name>
            <url-pattern>/*</url-pattern>
        </filter-mapping>-->
        
    </web-app>
    i got this error:

    Code:
    type Exception report
    
    message
    
    description The server encountered an internal error () that prevented it from fulfilling this request.
    
    exception
    
    org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'sessionFactory' is defined
    	org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:529)
    	org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1095)
    	org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:277)
    	org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    	org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1097)
    	org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.lookupSessionFactory(OpenSessionInViewFilter.java:242)
    	org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.lookupSessionFactory(OpenSessionInViewFilter.java:227)
    	org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:171)
    	org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
    note The full stack trace of the root cause is available in the Apache Tomcat/7.0.27 logs
    i have no idea, because a have sessionFactory in my dispatcher-servlet.xml.
    I haven't read the spring transaction docs yet but read several tutorials how to make spring mvc app and did exactly the same stuff. Please help, thnx.
    Last edited by SergeBud; Jan 11th, 2013 at 09:23 AM.

  2. #2
    Join Date
    Jan 2013
    Posts
    6

    Default

    dispatcher-servlet.xml:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:p="http://www.springframework.org/schema/p"
           xmlns:aop="http://www.springframework.org/schema/aop"
           xmlns:tx="http://www.springframework.org/schema/tx"
           xmlns:context="http://www.springframework.org/schema/context"
           xmlns:mvc="http://www.springframework.org/schema/mvc"
           xmlns:jee="http://www.springframework.org/schema/jee"
           xmlns:lang="http://www.springframework.org/schema/lang"
           xmlns:util="http://www.springframework.org/schema/util"
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
                               http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
                               http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
                               http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
                               http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
                               http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
                               http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
                               http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
           
        <mvc:annotation-driven />
        <context:component-scan base-package="by" />
        
        <mvc:resources mapping="/resources/**" location="/resources/" />
        
        <bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/>
    
        <bean id="viewResolver"
              class="org.springframework.web.servlet.view.InternalResourceViewResolver"
              p:prefix="/WEB-INF/jsp/"
              p:suffix=".jsp" />
        
        <bean id="propertyConfigurer"
            class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
            <property name="ignoreUnresolvablePlaceholders" value="true" />
            <property name="locations">
                <value>jdbc.properties</value>
            </property>
        </bean>
        
        <bean id="dataSource"
            class="org.springframework.jdbc.datasource.DriverManagerDataSource">
            <property name="driverClassName" value="${jdbc.driverClassName}" />
            <property name="url" value="${jdbc.url}" />
            <property name="username" value="${jdbc.username}" />
            <property name="password" value="${jdbc.password}" />
        </bean>
    
        <bean id="sessionFactory"
            class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
            <property name="dataSource" ref="dataSource"/>
    
            <property name="hibernateProperties">
                <props>
                    <prop key="hibernate.dialect">${jdbc.dialect}</prop>
                    <prop key="hibernate.show_sql">${jdbc.show_sql}</prop>
                    <prop key="hibernate.current_session_context_class">thread</prop>
                </props>
            </property>
    
        </bean>
        
        <bean id="transactionManager"
                class="org.springframework.orm.hibernate3HibernateTransactionManager">
                <property name="sessionFactory" ref="sessionFactory" />
        </bean>
    
    <!--    Transaction manager -->
        <tx:annotation-driven transaction-manager="transactionManager" />
        
    </beans>
    So when i run my application, i've got this error:

    Code:
    type Exception report
    
    message
    
    description The server encountered an internal error () that prevented it from fulfilling this request.
    
    exception
    
    org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'sessionFactory' is defined
    	org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:529)
    	org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1095)
    	org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:277)
    	org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    	org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1097)
    	org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.lookupSessionFactory(OpenSessionInViewFilter.java:242)
    	org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.lookupSessionFactory(OpenSessionInViewFilter.java:227)
    	org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:171)
    	org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
    note The full stack trace of the root cause is available in the Apache Tomcat/7.0.27 logs.
    I don't understand? what's wrong, because i have sessionFactory in my dispatch-servlet.xml. I've just begun studing spring+hibernate. I haven't read the Spring Transaction docs yet.

    Please somebody help, can't solve this problem for 3 days

  3. #3
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    I don't understand? what's wrong, because i have sessionFactory in my dispatch-servlet.xml.
    Which is wrong...

    The OpenSessionInViewFilter only has access to beans in the root context not beans defined in the servlets (there can be many dispatcherservlets so which one to use in that case?!). In general you want your central beans in your root context and only the web related stuff in the dispatcherservlet.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  4. #4
    Join Date
    Jan 2013
    Posts
    6

    Default

    Quote Originally Posted by Marten Deinum View Post
    Which is wrong...

    The OpenSessionInViewFilter only has access to beans in the root context not beans defined in the servlets (there can be many dispatcherservlets so which one to use in that case?!). In general you want your central beans in your root context and only the web related stuff in the dispatcherservlet.
    I saw another example which worked OK. It contained 2 xml files: dispatcher-servlet.xml and new created dal.xml. This dal.xml included the description
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    	xmlns:tx="http://www.springframework.org/schema/tx"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans 
    	http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
    	http://www.springframework.org/schema/context
            http://www.springframework.org/schema/context/spring-context.xsd 
            http://www.springframework.org/schema/tx 
            http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
    
    	<context:component-scan base-package="by.lesson11.dal" />
    
    	<bean id="propertyConfigurer"
    		class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    		<property name="ignoreUnresolvablePlaceholders" value="true" />
    		<property name="locations">
    			<list>
    				<value>classpath:jdbc.properties</value>
    			</list>
    		</property>
    	</bean>
    
    	<bean id="dataSource"
    		class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    		<property name="driverClassName" value="${jdbc.driverClassName}" />
    		<property name="url" value="${jdbc.url}" />
    		<property name="username" value="${jdbc.username}" />
    		<property name="password" value="${jdbc.password}" />
    	</bean>
    
    	<bean id="sessionFactory"
    		class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    		<property name="dataSource" ref="dataSource"></property>
    		<property name="hibernateProperties">
    			<props>
    				<prop key="hibernate.dialect">${hibernate.dialect}</prop>
    				<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
    			</props>
    		</property>
    		<property name="packagesToScan" value="by.lesson11.entity"></property>
    	</bean>
    
    	<bean id="transactionManager"
    		class="org.springframework.orm.hibernate4.HibernateTransactionManager">
    		<property name="sessionFactory" ref="sessionFactory" />
    	</bean>
    
    	<!--Transaction manager -->
    	<tx:annotation-driven transaction-manager="transactionManager" />
    </beans>
    and dispatcher-servlet.xml had the only string <import resource="dal.xml" />
    That's why i decided, that it doesn't matter if this description will be in dispatcher-servlet.xml or in another file.
    So how can i get the access to the root context i don't understand.

  5. #5
    Join Date
    Jan 2013
    Posts
    6

    Default

    Oh finally understood what you meant
    I have changed my web.xml a little:
    add this ->
    Code:
    <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>
               /WEB-INF/applicationContext.xml
            </param-value>
        </context-param>
    add deleted this (what is commented out) ->
    Code:
    <servlet>
            <servlet-name>dispatcher</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <!--        <init-param>
                <param-name>contextConfigLocation</param-name>
                <param-value>/WEB-INF/dispatcher-servlet.xml</param-value>
            </init-param>-->
            <load-on-startup>2</load-on-startup>
        </servlet>
    add copied the description of configurations
    Code:
    <context:component-scan base-package="by.DAO" />
        
        <bean id="propertyConfigurer"
            class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
            <property name="ignoreUnresolvablePlaceholders" value="true" />
            <property name="locations">
                <value>jdbc.properties</value>
            </property>
        </bean>
        
        <bean id="dataSource"
            class="org.springframework.jdbc.datasource.DriverManagerDataSource">
            <property name="driverClassName" value="${jdbc.driverClassName}" />
            <property name="url" value="${jdbc.url}" />
            <property name="username" value="${jdbc.username}" />
            <property name="password" value="${jdbc.password}" />
        </bean>
    
        <bean id="sessionFactory"
            class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
            <property name="dataSource" ref="dataSource"/>
    
            <property name="hibernateProperties">
                <props>
                    <prop key="hibernate.dialect">${jdbc.dialect}</prop>
                    <prop key="hibernate.show_sql">${jdbc.show_sql}</prop>
                    <prop key="hibernate.current_session_context_class">thread</prop>
                </props>
            </property>
    
        </bean>
        
        <bean id="transactionManager"
                class="org.springframework.orm.hibernate3.HibernateTransactionManager">
                <property name="sessionFactory" ref="sessionFactory" />
        </bean>
    
    <!--    Transaction manager -->
        <tx:annotation-driven transaction-manager="transactionManager" />
    to my applicationContext.xml.
    The i built my app and deployed it and finally i got another (i'm so happy !!!) another exception
    it's
    Code:
    SEVERE: Servlet.service() for servlet [dispatcher] in context with path [/GamePortal2] threw exception [Request processing failed; nested exception is org.hibernate.HibernateException: createQuery is not valid without active transaction] with root cause
    org.hibernate.HibernateException: createQuery is not valid without active transaction
    Now i begin to read Transaction Docs and try to find out what's wrong now

  6. #6
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    As mentioned earlier your web related stuff should be loaded by the dispatcher servlet. Also your commenting out in the web.xml has no effect... The DispatcherServlet, by default, loads an xml file named [servletname]-servlet.xml so in your case the dispatcher-servlet.xml will still get loaded, resulting in duplication of the beans.

    The same applies for your added context parameter that is also the default file loaded by the ContextLoaderListener.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  7. #7
    Join Date
    Jan 2013
    Posts
    6

    Default

    May be but now i haven't this stupid sessionFactory error and can go further. And now my error is this:
    Code:
    янв 14, 2013 2:49:19 PM org.apache.catalina.core.ApplicationContext log
    INFO: No Spring WebApplicationInitializer types detected on classpath
    янв 14, 2013 2:49:19 PM org.apache.catalina.core.ApplicationContext log
    INFO: Initializing Spring root WebApplicationContext
    янв 14, 2013 2:49:24 PM org.apache.catalina.core.ApplicationContext log
    INFO: Initializing Spring FrameworkServlet 'dispatcher'
    янв 14, 2013 2:49:28 PM org.apache.catalina.core.StandardWrapperValve invoke
    SEVERE: Servlet.service() for servlet [dispatcher] in context with path [/GamePortal2] threw exception [Request processing failed; nested exception is org.hibernate.hql.ast.QuerySyntaxException: News is not mapped [from News]] with root cause
    org.hibernate.hql.ast.QuerySyntaxException: News is not mapped [from News]
    	at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:158)
    	at org.hibernate.hql.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:87)
    	at org.hibernate.hql.ast.tree.FromClause.addFromElement(FromClause.java:70)
    	at org.hibernate.hql.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:255)
    	at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3056)
    	at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:2945)
    	at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:688)
    	at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:544)
    	at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:281)
    	at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:229)
    	at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:228)
    	at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:160)
    	at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111)
    	at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
    	at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
    	at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
    	at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
    	at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
    	at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1623)
    	at by.DAO.NewsDAOImpl.listNews(NewsDAOImpl.java:43)
    	at by.service.NewsServiceImpl.listNews(NewsServiceImpl.java:45)
    	at by.controllers.PagesController.goHome(PagesController.java:26)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:601)
    	at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:213)
    	at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
    	at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
    	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
    	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
    	at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
    	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
    	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
    	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
    	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    	at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    	at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
    	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
    	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
    	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
    	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)
    	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)
    	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
    	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    	at java.lang.Thread.run(Thread.java:722)
    here is my hibernate.cfg.xml ->
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
    <hibernate-configuration>
      <session-factory>
            <mapping class="by.Entity.News" />
            <property name="hibernate.connection.driver_class">org.h2.Driver</property>
            <property name="hibernate.connection.url">jdbc:h2:file:c:/MyProjDb/mainDB.h2.db</property>
            <property name="hibernate.connection.username">serge</property>
      </session-factory>
    </hibernate-configuration>
    i've tried to write "mapping class" and "mapping package" but no success
    And i noticed that my hibernate version isn't 3.5 it's 3.2.5
    May be make sense to change it to more new one ?
    Last edited by SergeBud; Jan 14th, 2013 at 06:51 AM.

  8. #8
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    I strongly suggest a forum search as the last 2 questions you asked have been answered numerous times before.

    Code:
    <bean id="sessionFactory"
            class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
            <property name="dataSource" ref="dataSource"/>
    
            <property name="hibernateProperties">
                <props>
                    <prop key="hibernate.dialect">${jdbc.dialect}</prop>
                    <prop key="hibernate.show_sql">${jdbc.show_sql}</prop>
                    <prop key="hibernate.current_session_context_class">thread</prop>
                </props>
            </property>
    
        </bean>
    Remove highlighted line.

    Also duplicate beans can lead to strange side effects so I strongly suggest you first fix your configuration before moving on.

    The error indicates that it cannot find the News entity when using mapping-class be aware that you have the correct annotations on that class else you need a hibernate mapping file (hbm file).

    However I strongly suggest using google and the forum search because, as mentioned earlier, these questions have been answered before.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  9. #9
    Join Date
    Jan 2013
    Posts
    6

    Default

    Thanks for advice. Yesterday solved the problem. In my NewsServiceImpl.java changed the line :
    BEFORE ->
    Code:
    @Override
        public List<News> listNews() {
            return sessionFactory.getCurrentSession().createQuery("from News").list();// error was pointed at this line
        }
    AFTER ->
    Code:
    @Override
        public List<News> listNews() {
            return sessionFactory.getCurrentSession().createCriteria(News.class).list();
        }
    And in the end my app deployed without errors It's very strange but now it doesn't matter for me because i have to show my project next week that's why i just have no time to seek what the real problem is. But whatever thank you a lot i really appreciate your help and time.

Posting Permissions

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