我知道有很多关于这个错误的帖子。但对我来说似乎什么都不管用。我在entitymanager.flush()上获得transactionrequiredexception
我有配置类`
@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(
entityManagerFactoryRef = “msEntityManagerFactory",
transactionManagerRef = “msTransactionManager",
basePackages = {
x, y, z
})
public class msConfig {
@Bean(name = “msDataSource")
@ConfigurationProperties(prefix = "postgres.datasource.hikari")
public DataSource msDataSource() {
return DataSourceBuilder.create().build();
}
@Bean(name = “msEntityManagerFactory")
public LocalContainerEntityManagerFactoryBean entityManagerFactory(
EntityManagerFactoryBuilder entityManagerFactoryBuilder,
@Qualifier(“msDataSource") DataSource dataSource) {
Properties properties = new Properties();
properties.setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect");
LocalContainerEntityManagerFactoryBean entityManager = entityManagerFactoryBuilder
.dataSource(dataSource)
.packages(“x”,”y”, “z”)
.persistenceUnit("postgres")
.build();
entityManager.setJpaProperties(properties);
return entityManager;
}
@Bean(name = “msTransactionManager")
public PlatformTransactionManager transactionManager(@Qualifier(“msEntityManagerFactory") EntityManagerFactory entityManagerFactory) {
return new JpaTransactionManager(entityManagerFactory);
}
}
`
在我的服务课上,我从上面的课上注入了一个完整的管理者
public Dummy(@Qualifier(“msEntityManagerFactory") EntityManager entityManager) {
this.entityManager = entityManager;
}
在同一个类中,我有另一个标记为@transactional的方法,并且 entityManager.flush()
少了什么?
编辑:
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:3398)
at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1355)
at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1350)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:366)
at com.sun.proxy.$Proxy220.flush(Unknown Source)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:314)
at com.sun.proxy.$Proxy220.flush(Unknown Source)
暂无答案!
目前还没有任何答案,快来回答吧!