Skip to content

@Primary not working for LocalContainerEntityManagerFactoryBean #24097

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

Closed
CalebSLane opened this issue Nov 28, 2019 · 1 comment
Closed

@Primary not working for LocalContainerEntityManagerFactoryBean #24097

CalebSLane opened this issue Nov 28, 2019 · 1 comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: duplicate A duplicate of another issue

Comments

@CalebSLane
Copy link

Present in Spring 5.1.2.RELEASE

Created 2 beans of type LocalContainerEntityManagerFactoryBean, annotated one with @Primary. Neither EntityManager proxy (of type SharedEntityManagerCreator$SharedEntityManagerInvocationHandler) gets marked as primary when trying to get it through @Autowired

Seems related to issue #22675

Beans goes through DefaultListableBeanFactory.isPrimary() with beanName as "org.springframework.orm.jpa.SharedEntityManagerCreator#0" and "org.springframework.orm.jpa.SharedEntityManagerCreator#1". Both do not start with a factory dereference prefix, so isPrimary() does not check the Bean's parent BeanFactory for the @primary annotation, so the running application cannot decide which to autowire.

@snicoll
Copy link
Member

snicoll commented Sep 26, 2023

Present in Spring 5.1.2.RELEASE

The issue that you've referenced has been fixed in Spring Framework 5.2.x. If you can reproduce with a supported version of the framework, please attach a small sample that we can run ourselves and we can reopen.

@snicoll snicoll closed this as not planned Won't fix, can't repro, duplicate, stale Sep 26, 2023
@snicoll snicoll added status: duplicate A duplicate of another issue and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Sep 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

4 participants