- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的 Controller 如下:
@GetMapping("/groupByCourse")
public Reply getStudentsCountByCourse(){
Reply reply=new Reply();
reply.setData(service.getStudentsCountByCourse());
return reply;
}
服务是:-
public List getStudentsCountByCourse() {
List students=new ArrayList<>();
students=studentCourseRepo.findCountStudentByCourse();
getCourseCountByStudent();
return students;
}
@Transactional(Transactional.TxType.REQUIRES_NEW)
public List getCourseCountByStudent() {
List students=new ArrayList<>();
students=studentCourseRepo.findCountCourseByStudent();
return students;
}
存储库是:-
@Repository
public interface StudentCourseRepo extends CrudRepository<StudentCourseTbl, StudentCourseTblPK> {
@Query(value = "select sc.studentCourseTblPK.courseId,count(sc.studentCourseTblPK.studentId) from StudentCourseTbl sc group by sc.studentCourseTblPK.courseId")
List findCountStudentByCourse();
@Lock(LockModeType.PESSIMISTIC_WRITE)
@Query(value = "select s.id,s.name,count(sc.studentCourseTblPK.courseId) from StudentCourseTbl sc right join StudentsTbl s on sc.studentCourseTblPK.studentId=s.id group by s.id")
List findCountCourseByStudent();
}
我已经在我的服务方法中使用 @Transactional(Transactional.TxType.REQUIRES_NEW) 来使用 Pessimistic_write 锁执行查询,但即使在事务模式设置为需要新之后,我仍然收到 TransactionRequiredException 。我知道我可以通过在 getStudentsCountByCourse 方法上使用 @Transactional 注释来使代码工作,但我想知道它当前不起作用的原因。
我使用的是springboot版本2.1.7.Release,数据库为mysql
最佳答案
这是 Spring 默认 CGLIB 代理的已知限制。由于事务行为是基于代理的,因此目标对象的一个方法调用另一个方法不会导致事务行为,即使后一个方法被标记为事务性的。
可以通过在字节码中编织事务行为而不是使用代理(即使用 AspectJ)来避免这种情况。
您可以在此处阅读有关 Spring 事务管理的更多信息 Method visibility and @Transactional
关于java - Spring Boot 中的 TransactionRequiredException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58138538/
当我尝试使用 Hibernate 的多线程从数据库中删除数据时遇到问题。 repo : @Modifying @Query("DELETE FROM Customer cus WHERE cus.c
我在日志中收到异常: javax.persistence.TransactionRequiredException: Executing an update/delete query 这位于 upda
我正在运行 Karaf,我在 persistence.xml 中有一个数据源(指向 SQL Server DB),并且我正在尝试执行插入查询。 但是我遇到了这个异常: javax.persistenc
Spring MVC应用程序使用SpringDataJPA和休眠模式。生产模式利用了MySQL,但是对于单元测试,我已经设置了H2DB来运行,并且都使用单独的Java配置。该应用程序还利用了Sprin
这是我的存储库配置: @Configuration public class RepositoryConfing { @Bean public LocalContainerEntity
我有一个使用 Spring、Hibernate 和 JTA 的应用程序。 我们收到了一个数据大于预期的请求(10000 个元素),一般请求是 10-100 个元素。 在处理这个请求时,我们尝试在数据库
您好,我正在使用带有 spring 和 mongodb 的 hibernate JPA,并且我正在 Glassfish-4.0 上运行我的应用程序。 我的服务等级是: @Component publi
我正在尝试在 spring 中编写 2 个 native SQL 查询, 我在服务类中使用 SQL 的查询注释是: @Transactional @Scheduled(cron = "
我的 Controller 如下: @GetMapping("/groupByCourse") public Reply getStudentsCountByCourse(){
我正在开发一个简单的应用程序,其中数据库中的用户记录显示在 primefaces 数据表中,用户可以编辑或删除这些记录。这是 jsf 文件
我有异常(exception) javax.persistence.TransactionRequiredException: No transactional EntityManager ava
您好,我创建了一个简单的 JSF + JPA 应用程序。我的网络应用程序由一个 Entity、一个 ManagedBean 和一些 JSF 页面组成。它的目的是在 MySQL 数据库中创建和存储一个对
我想通过一个查询删除三个表中的相关数据。我收到错误消息:javax.persistence.TransactionRequiredException:执行更新/删除查询 我们使用 java 8、Hib
我有一个 Spring4 网络应用程序。最初我使用的是 Hibernate SessionFactory,并使用 Spring Hibernate API 进行开发。一切正常。也许愚蠢的是,我最近决定
TransactionRequiredException 的可能原因是什么? javax.ejb.EJBTransactionRolledbackException: JBAS011469: Tran
我有一个 CrudRepository 和一个删除数据的方法: public interface SampleRepository extends PagingAndSortingRepository
我有一个接受 POST 请求的 servlet,并且我正在尝试使用请求的参数来构建并保留实体类的实例。 这是我的 servlet: public class TheServlet extends Ht
我有以下类来使用实体管理器批量保存实体: @Repository @Transactional public class AbstractRepositoryAdapter { private
我有一个以 Hibernate 作为持久性提供者的 Spring/JPA 配置。但是我不明白为什么当我在没有打开事务的情况下对以下 DAO 代码调用 save() 时没有抛出 TransactionR
我有一个 Spring Boot 2 应用程序(仍处于开发阶段)与 JPA、hibernate 等一起运行良好。我现在进行的单一持久性测试通过正常。 但是,当我添加 @EnableBatchProce
我是一名优秀的程序员,十分优秀!