Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Circular dependencies when using @EntityListeners #59

Open
s-seidel opened this issue Jul 14, 2021 · 0 comments
Open

Circular dependencies when using @EntityListeners #59

s-seidel opened this issue Jul 14, 2021 · 0 comments

Comments

@s-seidel
Copy link

s-seidel commented Jul 14, 2021

What steps will reproduce the problem?
Steps to reproduce the behavior:
I have an Entity with a Listener:

@Entity
@EntityListeners(MyEntityUpdateListener.class)
public class MyEntity {
...

and the Listener needs to modify the database, so it needs a Repository or the entityManager:

public class MyEntityUpdateListener {
    private final EntityManager entityManager;

    public MyEntityUpdateListener(EntityManager _em) {
...

When starting this, I get

***************************
APPLICATION FAILED TO START
***************************

Description:

The dependencies of some of the beans in the application context form a cycle:

...
      ↓
   myRepository defined in ....MyRepository defined in @EnableJpaRepositories declared on MyApplication
      ↓
   (inner bean)#55e91e61
┌─────┐
|  entityManagerFactory defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]
↑     ↓
|  ....MyEntityUpdateListener
↑     ↓
|  org.springframework.orm.jpa.SharedEntityManagerCreator#0
└─────┘

What is the expected output?

This works fine with standard Spring Boot.

What happens instead?

Should also work with spring-data-jpa-entity-graph

Environment:

  • Spring Data JPA version (not the Spring Boot one): 2.3.4.RELEASE
  • ORM with version: 5.4.21.Final
  • spring-data-jpa-entity-graph version: 2.3.1, 2.4.2, 2.5.0

Things I have tried (none have worked):

  • change from constructor injection to @Autowired - variable will be null
  • change from EntityManager to requiring a Repository - no change
  • use @PostUpdate annotation in the Entity class - same error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants