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

Mixing user-supplied, application-managed EntityManagers with container-managed EntityManagers may not work #4929

Closed
ljnelson opened this issue Sep 21, 2022 · 3 comments · Fixed by #9145
Assignees
Labels
1.x Issues for 1.x version branch 2.x Issues for 2.x version branch 3.x Issues for 3.x version branch 4.x Version 4.x bug Something isn't working jpa/jta MP P1

Comments

@ljnelson
Copy link
Member

Container-managed EntityManagers with a given qualifier and user-managed EntityManagers with the same qualifier seemingly prevent injection of any EntityManager with that qualifier. This is an edge use case but should be supported.

@ljnelson ljnelson added bug Something isn't working MP P1 jpa/jta 1.x Issues for 1.x version branch 2.x Issues for 2.x version branch 3.x Issues for 3.x version branch 4.x Version 4.x labels Sep 21, 2022
@ljnelson ljnelson self-assigned this Sep 21, 2022
@ljnelson
Copy link
Member Author

ljnelson commented Nov 8, 2022

(Moved out of sprint scope to high priority only because I'm working on #4928 first.)

@ljnelson
Copy link
Member Author

ljnelson commented Dec 6, 2022

I understand the root issue. In this block:

for (final Set<Annotation> qualifiers : this.persistenceUnitQualifiers) {
addContainerManagedEntityManagerFactoryBeans(event, qualifiers, beanManager);
}
if (this.transactionsSupported) {
for (final Set<Annotation> qualifiers : this.persistenceContextQualifiers) {
// Note that each add* method invoked below is
// responsible for ensuring that it adds beans only
// once if at all, i.e. for validating and
// de-duplicating the qualifiers that it is supplied
// with if necessary.
addContainerManagedEntityManagerFactoryBeans(event, qualifiers, beanManager);
addCdiTransactionScopedEntityManagerBeans(event, qualifiers);
if (qualifiers.contains(Extended.Literal.INSTANCE)) {
addExtendedEntityManagerBeans(event, qualifiers, beanManager);
} else {
assert qualifiers.contains(JpaTransactionScoped.Literal.INSTANCE);
addNonTransactionalEntityManagerBeans(event, qualifiers, beanManager);
addJpaTransactionScopedEntityManagerBeans(event, qualifiers);
}
}
} else {
for (final Set<Annotation> qualifiers : this.persistenceContextQualifiers) {
// Note that each add* method invoked below is
// responsible for ensuring that it adds beans only
// once if at all, i.e. for validating the qualifiers
// that it is supplied with.
addContainerManagedEntityManagerFactoryBeans(event, qualifiers, beanManager);
}
}

…it will "fire" if the user has written, for example:

@Inject
@SomeUserDefinedQualifierOrNot
private EntityManagerFactory emf;

…which is incorrect. The block should "fire" only if @ContainerManaged is also present, which will happen only when the user has written:

@PersistenceUnit // rewritten internally to @Inject @ContainerManaged
@SomeUserDefinedQualifierOrNot
private EntityManagerFactory emf;

It is likely but not guaranteed that a fix for this will be delivered in PR(s) that address #4928.

@m0mus m0mus added this to Backlog Aug 12, 2024
@m0mus m0mus moved this to Sprint Scope in Backlog Aug 12, 2024
@ljnelson
Copy link
Member Author

Indeed this works just fine with Eclipselink (when you introduce an application-managed EntityManagerFactory creation via Persistence.createEntityManagerFactory("someUnitName")). As expected and as is usual, Hibernate breaks, looking for some reason for JNDI. Investigating.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.x Issues for 1.x version branch 2.x Issues for 2.x version branch 3.x Issues for 3.x version branch 4.x Version 4.x bug Something isn't working jpa/jta MP P1
Projects
Archived in project
1 participant