Results 1 to 3 of 3

Thread: Newbie: "No Hibernate Session bound to thread"

  1. #1
    Join Date
    Jul 2006
    Posts
    5

    Default Newbie: "No Hibernate Session bound to thread"

    Hi, I´m just starting using Hibernate and Spring and now I´m facing this problem:
    Here is my configuration file:

    <!-- DataSource wich will be used by Hibernate -->
    <bean id="datasourceHibernate" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <property name="driverClassName" value="com.mysql.jdbc.Driver" />
    <property name="url" value="jdbc:mysql:theserver/thedatabase" />
    <property name="username" value="user" />
    <property name="password" value="password" />
    </bean>

    <!-- Hibernate´s SessionFactory -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean">
    <property name="dataSource" ref="datasourceHibernate" />
    <property name="mappingResources">
    <list>
    <value>ecm/cmt/Disciplina.hbm.xml</value>
    </list>
    </property>

    <property name="hibernateProperties">
    <value>
    hibernate.dialect=org.hibernate.dialect.MySQLDiale ct
    hibernate.current_session_context_class=thread
    hibernate.show_sql=true
    hibernate.format_sql=true transaction.factory_class=net.sf.hibernate.transac tion.JDBCTransactionFactory

    </value>
    </property>
    </bean>

    When I try to persist any object using Hibernate + Spring using this configuration, I´m getting the following error message:
    "No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here"

    What am I doing wrong here?

  2. #2

    Default

    How are you using hibernate? Are you using HibernateDAOSupport? Where do you inject your session and how are you using them? Could you post some piece of code?

    Regards

  3. #3

    Default I'm getting this, too

    I'm seeing this same behavior, after following online examples on setting this up in a servlet container environment.

    My DAO inherits from HibernateDaoSupport, and I call getSession(false) to get the session. At that point, I get the following exception. Note that up to now, I've made NO explicit Hibernate calls.

    My setup is a bit different: I use AnnotationSessionFactoryBean, and I get my data source from JNDI. Prior to trying to use Hibernate, I was successfully using Spring's JDBC data access support.

    Code:
    18:53:21.713 DEBUG   org.springframework.web.servlet.FrameworkServlet (FrameworkServlet.java:413) Could not complete request
    java.lang.IllegalStateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
    	at org.springframework.orm.hibernate3.SessionFactoryUtils.doGetSession(SessionFactoryUtils.java:357)
    	at org.springframework.orm.hibernate3.SessionFactoryUtils.getSession(SessionFactoryUtils.java:189)
    	at org.springframework.orm.hibernate3.support.HibernateDaoSupport.getSession(HibernateDaoSupport.java:169)
    	at com.mycompany.myprod.bus.MyDAO.save(MyDAO.java:95)
    ...

Posting Permissions

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