Я работаю с Spring 3.0.5, Hibernate 3.3 и generic-hibernate-dao . Я настроил Hibernate SessionFactory как показано ниже:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean?">
<property name="dataSource">
<ref local="dataSource" />
</property>
<property name="packagesToScan" value="com.xxx.re.admin.model" /> <property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.hbm2ddl.auto">validate</prop>
</props>
</property>
</bean>
<!-- Transaction manager for a single Hibernate SessionFactory? (alternative
to JTA) -->
<tx:annotation-driven />
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager?">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
Я создал BaseDAOImpl и расширил домен DAO, как показано ниже:
public class BaseDAOImpl<T, ID extends Serializable> extends GenericDAOImpl<T, ID> {
@Autowired @Override public void setSessionFactory(SessionFactory? sessionFactory) {
super.setSessionFactory(sessionFactory);
}
}
@Repository public class LocaleDAOImpl extends BaseDAOImpl<Locale, Long> implements LocaleDAO {
}
При доступе к контроллеру пружины (вызов dao.findAll()
) я получаю следующую ошибку:
org.hibernate.HibernateException?:
No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here.