Spring @PostUpdate和@PostPersist导致无限循环

Spring @PostUpdate和@PostPersist导致无限循环,spring,spring-boot,jpa,spring-data-jpa,Spring,Spring Boot,Jpa,Spring Data Jpa,在数据库中持久化实体后,需要执行一些操作。该操作还需要调用数据库以获取一些实体 为了执行该操作,我正在使用注释@PostUpdate和@PostPersist。 所以我的实体类看起来像 public class MyEntity implements Serializable { // some class fields // some methods @PostPersist @PostUpdate public void performAction

在数据库中持久化实体后,需要执行一些操作。该操作还需要调用数据库以获取一些实体

为了执行该操作,我正在使用注释
@PostUpdate
@PostPersist
。 所以我的实体类看起来像

public class MyEntity implements Serializable {

    // some class fields
    // some methods

    @PostPersist
    @PostUpdate
    public void performActionAfterPersist() {

        someService.performSomeAction(id);

    }
}
SomeService类如下所示:

public class SomeService {

    // some class fields
    // some methods

    public void performSomeAction(int id) {

        MyEntity myEntity = myEntityRepository.findById(id);
        // some other stuff done on myEntity

    }
}
只要调用了
findById
方法,它就会再次返回到用
@PostUpdate
@PostPersist
注释的方法

谁能告诉我为什么会发生这种情况,以及如何解决?有没有更好的办法