File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes Query about more than one  EntityManagerFactory in application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Query about more than one  EntityManagerFactory in application" Watch "Query about more than one  EntityManagerFactory in application" New topic
Author

Query about more than one EntityManagerFactory in application

hildich kilal
Ranch Hand

Joined: Aug 25, 2008
Posts: 44
In our application we are using a third party framework which creates its own EntityManagerFactory using some xyz-persistence.xml . The framework has its own classes to parse this xml and use EJB3Configuration class to create and EntityManagerFactory.

Now we dont want to use this. So what we have decided is to use simple default way to create EntityManagerFactory (using Persistence.createEntityManagerFactory which will read default persistence.xml in classpath)

Now both my application jar and other framework jar work in parallel.

So my question is can we create two different EntityManagerFactory pointing to same DB in one application? Can there be any issues , problems persistence managers from two EntitymanagerFactories start working parallel on same entity?


Please advise
Thanks









James Sutherland
Ranch Hand

Joined: Oct 01, 2007
Posts: 553
That should be fine.

If they are both doing connection pooling, then you may get twice the number of connections, unless you use a common DataSource.

If you are using a shared cache, then the objects in it could get stale. You could disable the shared cache, or use some sort of invalidation or coordination.

TopLink : EclipseLink : Book:Java Persistence : Blog:Java Persistence Performance
hildich kilal
Ranch Hand

Joined: Aug 25, 2008
Posts: 44
Thanks James,
That clarified my doubt. I am not using any connection pooling or any cache. I believe when you said cache you meant second level cache only?

Thanks
hildich
 
 
subject: Query about more than one EntityManagerFactory in application