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

closing entity managers #1

Open
webczat opened this issue Apr 12, 2019 · 3 comments
Open

closing entity managers #1

webczat opened this issue Apr 12, 2019 · 3 comments
Assignees

Comments

@webczat
Copy link

webczat commented Apr 12, 2019

Shouldn't entity managers be closed? I know that container managed entity managers cannot be closed by application as per the requirements stated in jpa spec. However, isn't it the case that the container should close it? entity managers are created by "EntityManagerFactory.createEntityManager" all the time, and these are described as creating application managed entity managers, so i guess container can close them, and would have to wrap them in a layer that prevents closing. Not sure how true that is.

@ljnelson
Copy link
Member

Hello and thanks for using microBean JPA CDI. As noted in the last paragraph of the README, this project is often deployed with a (necessarily) CDI-provider-specific counterpart (for Weld, this is microbean-jpa-weld-se). You'll note that the actual business of acquiring EntityManagers at runtime is not handled by this project, but by its counterpart.

It is not clear to me that an EntityManager created by the container with a JTA transaction type should ever be closed. Invoking operations on it when a transaction is not in effect will throw an error.

@ljnelson
Copy link
Member

For a similar take, see Wildfly's implementation. Note in particular that JTA EntityManagers are closed only when the transaction completes.

Additionally, I think that EclipseLink (as one example) "closes" the underlying machinery itself. See, for example:

https://github.com/eclipse-ee4j/eclipselink/blob/3668d1a81e3e13d28a63b930de10bece725b0ed5/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/transaction/AbstractSynchronizationListener.java#L236

I do need to track all this down and make sure that no resources are being leaked.

@ljnelson ljnelson self-assigned this Apr 15, 2019
@ljnelson
Copy link
Member

Glassfish does similar things.

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