Я получаю исключение ниже в моем приложении. Я использую hibernate 5.4.14 и Spring версии 4.3
javax.persistence.TransactionRequiredException: no transaction is in progress
at org.hibernate.internal.AbstractSharedSessionContract.checkTransactionNeededForUpdateOperation(AbstractSharedSessionContract.java:413)
at org.hibernate.internal.SessionImpl.checkTransactionNeededForUpdateOperation(SessionImpl.java:3387)
at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1343)
at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1339)
at org.springframework.orm.hibernate5.SessionFactoryUtils.flush(SessionFactoryUtils.java:144)
at org.springframework.orm.hibernate5.SpringSessionSynchronization.beforeCommit(SpringSessionSynchronization.java:95)
at org.springframework.transaction.support.TransactionSynchronizationUtils.triggerBeforeCommit(TransactionSynchronizationUtils.java:95)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerBeforeCommit(AbstractPlatformTransactionManager.java:936)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:748)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:734)
at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:518)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:292)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:671)
@ContextConfiguration(["/spring/example-test.xml", "/spring/example-i18n-context.xml", "/spring/example-data-context.xml"])
public abstract class CleanDataSpecification extends Specification {
@Resource(name = "exampleSF")
private SessionFactory exampleSf;
@ExampleTx
def cleanup() {
Session session = null
try {
Metamodel metamodel = exampleSf.getMetamodel()
Set metadata = metamodel.getEntities()
session = universitySf.openSession()
session.createSQLQuery("SET REFERENTIAL_INTEGRITY FALSE;").executeUpdate()
for (String entityName : metadata) {
println metamodel.getImportedClassName(entityName)
session.createQuery("DELETE FROM " + metamodel.getImportedClassName(entityName)).executeUpdate()
}
session.createSQLQuery("SET REFERENTIAL_INTEGRITY TRUE;").executeUpdate()
session.close()
} finally {
if (session != null && session.isOpen()) {
session.close()
}
}
}
}
Содержимое примера-теста. xml выглядит как
<code><pre>
<tx:annotation-driven transaction-manager="exampleTM" />
<bean id="exampleSF"
class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<qualifier value="example"/>
<property name="dataSource" ref="exampleDS"/>
<property name="hibernateProperties">
<props>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.H2Dialect</prop>
<!--<prop key="hibernate.current_session_context_class">thread</prop>-->
<prop key="jadira.usertype.autoRegisterUserTypes">true</prop>
<prop key="hibernate.hbm2ddl.auto">create-drop</prop>
<prop key="hibernate.cache.region.factory_class">
org.hibernate.cache.ehcache.EhCacheRegionFactory
</prop>
<prop key="hibernate.cache.use_second_level_cache">false</prop>
<prop key="hibernate.cache.use_query_cache">false</prop>
<prop key="net.sf.ehcache.configurationResourceName">hibernate/example-ehcache.xml</prop>
</props>
</property>
<property name="packagesToScan">
<value>com.test.portal.example.model</value>
</property>
</bean>
<bean id="exampleTM"
class =
"org.springframework.orm.hibernate5.HibernateTransactionManager">
<property name="sessionFactory" ref="exampleSF"/>
<qualifier value="example"/>
</bean>
Ни один из веб-ответы мне пока помогли. Любое предложение будет большим подспорьем.