0

I have question towards a best practice for configuration of persistence and cache (2nd lvl) within a maven multi module project with spring/jpa/ehcache. Only a single datasource is needed.

Lets assume

I have 3 domain maven modules containing only the entities:

  1. core_domain
  2. customers_domain (dependency core_domain)
  3. products_domain (dependency core_domain)

I also have 3 integration modules containing repositories:

  1. core_integr
  2. customers_integr (dependency customers_domain, core_integr)
  3. products_integr (dependency products_domain, core_integr)

Now these modules MAY eventually be combined into a single WAR.

One approach might be to define all persistence,transaction and caching configuration in the core_integr module. But this does not cleanly allow configuration per module. It's possible, but not clean.

Is it possible to have a persistence.xml and ehcache.xml per integration module? preferably while keeping spring configuration in the core_integr module. OR Do you really need to separate the spring config fully with multiple entitymanagers, persistence_units and cachemanagers all working against the single datasource?

Any advice is welcome.

Peter De Winter
  • 1,183
  • 2
  • 15
  • 27
  • Starting with Spring 3.1, the persistence.xml is no longer necessary. You could delegate that part into a context file in each of your modules. I don't know if the ehcache can exist several times. As far as I know only one CacheManager per classloader is allowed. But maybe? There is a similar question here: http://stackoverflow.com/questions/8834993/is-it-possible-to-use-multiple-ehcache-xml-in-different-projects-same-war - do you plan to cache the domain modules or introduce a cache on the integr layer? E.g. i would try to put the config as close to where it belongs. So tests may use the same – wemu Feb 11 '15 at 16:45
  • We are using websphere with jndi lookup of the entity manager configured in websphere. So we actually need a persistence.xml. – Peter De Winter Feb 11 '15 at 16:53

0 Answers0