Announcement Announcement Module
No announcement yet.
Simple Hibernate + Spring Injection - Help? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Simple Hibernate + Spring Injection - Help?

    Hi folks, I feel this should be really simple. I'm trying to avoid complexity. I had tried to get JPA working in a Spring managed app using AOP methodology, but it went down a very painful twisty road.

    All I'd like to do is have Hibernate manage my entities, using annotation. The problem I'm having is getting an active HibernateSession to my DAO. I'm hoping I can simply inject a HibernateSession directly, with the annotation factory, but I can't seem to get the right incantation. I'm getting for an error:

    org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
    	at org.springframework.orm.hibernate3.SpringSessionContext.currentSession(
    	at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(
    	at com.stonekeep.congo.dao.FriendDAO.add(
    The applicationContext.xml is definining my datasource (a C3PO pool) and my annotated classes. This should all just work - what am I missing?

      <bean class="com.stonekeep.congo.dao.FriendDAO">
    	<property name="dataSource" ref="com.stonekeep.congo.database.Pool"/>
    	<property name="sessionFactory">
    		<ref bean="sessionFactory" />
    <!-- Data sources -->
      <bean id="com.stonekeep.congo.database.Pool" class="com.mchange.v2.c3p0.ComboPooledDataSource"
        <property name="driverClass" value="${database.driver}"/>
        <property name="jdbcUrl" value="${database.url}"/>
        <property name="user" value="${database.user}"/>
        <property name="password" value="${database.password}"/>
        <property name="testConnectionOnCheckout" value="true"/>
      <!--  hibernate configuration -->
      <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    	<property name="dataSource">
    		<ref bean="com.stonekeep.congo.database.Pool" />
    	<property name="annotatedClasses">
    	<property name="hibernateProperties">
    			<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
    			<prop key="hibernate.generate_statistics">true</prop>
    			<prop key="hibernate.cache.use_query_cache">true</prop>
    			<prop key="hibernate.connection.release_mode">on_close</prop>
    			<prop key="hibernate.show_sql">true</prop>
    			<prop key="hibernate.cglib.use_reflection_optimizer">tru e</prop>
    			<prop key="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider</prop>
    			<prop key="hibernate.connection.autocommit">false</prop>
    			<prop key="hibernate.jdbc.batch_size">500</prop>
    Any help would be appreciated - cookies are available!

  • #2
    Please use the forum search, this question has been answered numerous times before...

    Short answer
    Configure transactions (a transactionamanger AND transactional configuration) without it you will not get transaction.


    • #3
      You should search on google to get a best result.

      Dịch vụ thiết kế nội thất văn pḥng luôn mang lại cho bạn một không gian nội thất văn pḥng đẹp và sang trọng
      Last edited by ct.nguyen00; Apr 20th, 2011, 03:05 AM.