Injection of EntityManager does not work with Lombok #1597
Comments
Does this work on the JVM but fails on native? |
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed. |
It works OK if I run it with But when springAot is true, the tests fail. |
@schauder @christophstrobl Please make sure this use case is working with upcoming Spring Boot 3 support if you think it is a valid one. |
Forgot to mention that the same error occurred in a result native image (both when building with Buildpacks and Native Build Tools). So, the error is not related to test only. |
image generates fine.. but fails because of EntityGraph Revisit after these two issues are fixed - spring-attic/spring-native#1729 - spring-attic/spring-native#1728 Found a temp workaround for EntityManager injection with lombok spring-attic/spring-native#1597
* attempting to generate native image image generates fine.. but fails because of EntityGraph Revisit after these two issues are fixed - spring-attic/spring-native#1729 - spring-attic/spring-native#1728 Found a temp workaround for EntityManager injection with lombok spring-attic/spring-native#1597 * will get this corrected in master branch * Merge branch 'master' into boot3-native # Conflicts: # src/main/java/gt/app/domain/AppUser.java * graalvm 22.3+ is required * h2 required at compile time for graalvm native compile * native image WIP * now it works ! * now it works ! * spring-attic/spring-native#1597 is resolved in spring boot 3 * spring-projects/spring-data-jpa#2681 is fixed * spring-projects/spring-data-jpa#2681 is fixed * spring-projects/spring-data-jpa#2681 is fixed
Spring Native is now superseded by Spring Boot 3 official native support, see the related reference documentation for more details. As a consequence, I am closing this issue, and recommend trying your use case with latest Spring Boot 3 version. If you still experience the issue reported here, please open an issue directly on the related Spring project (Spring Framework, Data, Security, Boot, Cloud, etc.) with a reproducer. Thanks for your contribution on the experimental Spring Native project, we hope you will enjoy the official native support introduced by Spring Boot 3. |
Using Spring Boot 2.6.7 (Web/JPA/Lombok) with Spring Native, when injecting EntityManager via a constructor injection, I'm getting a following error:
org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'javax.persistence.EntityManager' available: more than one 'primary' bean found among candidates: [org.springframework.orm.jpa.SharedEntityManagerCreator#0, org.springframework.orm.jpa.SharedEntityManagerCreator#1]
I have seen another issue opened with the same cause (#1372), but adding
@PersistenceContext
annotation did not help (IMHO this annotation is not relevant because this is a constructor-based injection).The sample app is on https://github.com/mnorsic/spring-native-jpa-demo, I have taken data-jpa sample and added a
FooService
, so it should be easily reproducible.EDIT: it works when using proposed solution from beforementioned ticket #1372 with
@PersistenceContext private EntityManager entityManager;
EDIT2: Yes, I'm aware of spring-projects/spring-framework#15076, but I don't have multiple persistence contexts, and Spring Data JPA allows constructor injection (spring-projects/spring-data-jpa#847).
The text was updated successfully, but these errors were encountered: