加载用户数据时出现以下错误。
org.hibernate.HibernateException: load is not valid without active transaction
我正在使用AspectJ编译时编织和弹簧3.O.和Hibernate 3.0
以下是我的代码和配置文件。
@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT)
public boolean add(User user) {
getUser(user)
}
public User getUser(User user) {
Session session = this.getSession();
User user = ( User ) session.load(User.class, 130);
return user;
}
配置:
<bean id="hbSessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
<property name="configurationClass">
<value>org.hibernate.cfg.AnnotationConfiguration</value>
</property>
</bean>
<!-- Initializes Transaction manager to handle hibernate transactions -->
<bean id="hbTxManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="hbSessionFactory" />
</bean>
<tx:annotation-driven mode="aspectj" transaction-manager="hbTxManager"/>
提前致谢