• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Query about more than one EntityManagerFactory in application

 
hildich kilal
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 553
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
hildich kilal
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic