|
Re: Multiple Entity Manager Factories? [message #1856347 is a reply to message #1856324] |
Mon, 05 December 2022 15:57 |
Chris Delahunt Messages: 57 Registered: December 2021 |
Member |
|
|
Generally it is better to reuse EntityManagerFactory instances yourself and handle the lifecycle rather than spin up new ones, but EclipseLink has some efficiencies to avoid re-loading and processing the persistence unit over and over if you don't. You will want to verify with a debugger, but EclipseLink uses EMFs to wrap ServerSessions and tie them to persistence units. Containers give different class loaders so that it can use entirely different persistence units, but outside of the container API, EclipseLink will be handing out EMF wrappers overtop of the same unit/serverSession. They should all be tied to the same ServerSession under the covers. This saves file loading, processing, and startup time, as most everything about them will be the same yet is very expensive to do on the fly. How this works in your Tomcat server will depend entirely on how you've deployed EclipseLink and its visibility to the application - statics depend on the class loader used to load them.
If you want/need truly independent EMFs, you can assign them different session names as a persistence property, which forces EclipseLink to create a new ServerSession for that name instead of reusing the one it might have on hand (which it names based on the persistence unit name and the class loader). Problems you might hit if you don't depend on what you do and what differences you expect on these EMFs. I don't remember the specifics, but the only time I needed distinct EMFs was in a project where I needed to handle multi tenancy myself on a per persistence unit basis - EclipseLink code could and can handle that though.
|
|
|
Powered by
FUDForum. Page generated in 0.03518 seconds