在spring配置文件中,我有以下bean:
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="EntryPU" />
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
当应用程序调用方法&#34;删除&#34;:
@Override
public void remove(int id) {
entry = entityManager.find(Entry.class, id);
entityManager.remove(entry);
}
日志说:
No transactional EntityManager available.
如何使其成为交易?
答案 0 :(得分:1)
将@Transactional添加到方法中,使其在事务中运行。
result.length