I am getting a "No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here" with Spring 3.2 with Hibernate 3.3
DAO class :
@Repository
public class ContactDAOImpl implements ContactDAO {
@Autowired
private SessionFactory sessionFactory;
public List<Contact> listContact() {
return sessionFactory.getCurrentSession().createQuery("from Contact").list();
}
......
}
}
Context configuration:
<beans .....>
<context:annotation-config />
<context:component-scan base-package="org.spring.*" />
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
.......
</bean>
<!-- Hibernate session factory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource"/>
</property>
<property name="annotatedClasses">
<list>
<value>org.spring.entity.Contact</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.SybaseDialect</prop>
<prop key="hibernate.show_sql">false</prop>
</props>
</property>
</bean>
Although I have defined TransactionManager,I do not use it anywhere.
Why am I getting the above error - when no place within my code uses or defines transactions?
Why am I forced to define a transaction?