Results 1 to 3 of 3

Thread: Simple Hibernate + Spring Injection - Help?

  1. #1
    Join Date
    Mar 2011
    Posts
    4

    Default 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:

    Code:
    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(SpringSessionContext.java:63)
    	at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:622)
    	at com.stonekeep.congo.dao.FriendDAO.add(FriendDAO.java:58)
    The applicationContext.xml is definining my datasource (a C3PO pool) and my annotated classes. This should all just work - what am I missing?

    Code:
      <bean class="com.stonekeep.congo.dao.FriendDAO">
    	<property name="dataSource" ref="com.stonekeep.congo.database.Pool"/>
    	<property name="sessionFactory">
    		<ref bean="sessionFactory" />
    	</property>
      </bean>
    
    <!-- Data sources -->
      <bean id="com.stonekeep.congo.database.Pool" class="com.mchange.v2.c3p0.ComboPooledDataSource"
        destroy-method="close">
        <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"/>
      </bean>
      
      <!--  hibernate configuration -->
      <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
      
    	<property name="dataSource">
    		<ref bean="com.stonekeep.congo.database.Pool" />
    	</property>
    	<property name="annotatedClasses">
    		<list>
    			<value>com.stonekeep.congo.data.Friend</value>
    		</list>
    	</property>
    	<property name="hibernateProperties">
    		<props>
    			<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>
    		</props>
        </property>
      </bean>
    Any help would be appreciated - cookies are available!

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

    Default

    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.
    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

  3. #3
    Join Date
    Mar 2011
    Posts
    1

    Default

    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 at 02:05 AM.

Tags for this Thread

Posting Permissions

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