0
我相信所有的配置是正確的,但我仍正在錯誤:春天Declartive交易沒有約束力
org.hibernate.HibernateException: save is not valid without active transaction
一些如何聲明性事務無法正常工作。你能指出什麼可能是問題。
以下是我的配置:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">
<aop:aspectj-autoproxy />
<context:property-placeholder location="classpath:application.properties" />
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource" >
<property name="driverClassName" value="${connection.driverclass}" />
<property name="url" value="${connection.url}" />
<property name="username" value="${connection.username}" />
<property name="password" value="${connection.password}" />
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocations">
<list>
<value>classpath:hibernate.cfg.xml</value>
</list>
</property>
</bean>
<bean id="baseDao" class="edu.hibernate.self.learning1.dao.impl.BaseDAO">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="employeeDAO" class="edu.hibernate.self.learning1.dao.impl.EmployeeDAOImpl"
parent="baseDao" />
<bean id="h1TransactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="employeeService"
class="edu.hibernate.self.learning1.service.impl.EmployeeServiceImpl">
<property name="employeeDAO" ref="employeeDAO" />
</bean>
<tx:advice id="txAdviceEmpService" transaction-manager="h1TransactionManager">
<tx:attributes>
<tx:method name="saveNewEmployee" propagation="REQUIRED" read-only="false" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:advisor
pointcut="execution(* edu.hibernate.self.learning1.service.impl.EmployeeServiceImpl.*(..))"
advice-ref="txAdviceEmpService" />
</aop:config>
</beans>
服務層:
public class EmployeeServiceImpl implements EmployeeService {
private EmployeeDAO employeeDAO;
@Override
public Employee saveNewEmployee(Employee employee) {
return employeeDAO.saveNewEmployee(employee);
}
public EmployeeDAO getEmployeeDAO() {
return employeeDAO;
}
public void setEmployeeDAO(EmployeeDAO employeeDAO) {
this.employeeDAO = employeeDAO;
}
}
回購層:
public class EmployeeDAOImpl extends BaseDAO implements EmployeeDAO {
@Override
public Employee saveNewEmployee(Employee employee) {
employee = (Employee) getCurrentSession().save(employee);
getCurrentSession().flush();
return employee;
}
}
期待着一些迴應。
沒有。沒有成功。 – Debopam