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:
The applicationContext.xml is definining my datasource (a C3PO pool) and my annotated classes. This should all just work - what am I missing?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)
Any help would be appreciated - cookies are available!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>


Reply With Quote
