У нас есть несколько maven проектов, которые наследуются друг от друга. У pom нашего уровня персистентности есть следующие зависимости:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${dep.hibernate.version}</version>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-core</artifactId>
<version>2.4.3</version>
</dependency>
В настоящее время у меня есть файл persistence.xml, в том числе:
<persistence-unit name="MyModel" transaction-type="RESOURCE_LOCAL" >
<shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLInnoDBDialect"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>
<property name="hibernate.use_sql_comments" values="true"/>
<property name="hibernate.cache.region.factory_class" value="net.sf.ehcache.hibernate.EhCacheRegionFactory"/>
<property name="hibernate.cache.use_second_level_cache" value="true"/>
<property name="hibernate.cache.use_query_cache">true</property>
<property name="hibernate.generate_statistics" value="true"/>
</properties>
В моих модульных тестах для модельного проекта я могу заставить Hibernate загрузить фабрику региона ehcache. Однако я перехожу к дочернему проекту, который наследует этот (используя пружину для создания менеджера сущностей), и он не может найти фабрику регионов ehcache.
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: MyModel] Unable to build EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:912) ~[hibernate-entitymanager-3.6.2.Final.jar:3.6.2.Final]
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:74) ~[hibernate-entitymanager-3.6.2.Final.jar:3.6.2.Final]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:225) ~[spring-orm-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:308) ~[spring-orm-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477) ~[spring-beans-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417) ~[spring-beans-3.0.5.RELEASE.jar:3.0.5.RELEASE]
... 40 common frames omitted
Caused by: org.hibernate.HibernateException: could not instantiate RegionFactory [net.sf.ehcache.hibernate.EhCacheRegionFactory]
at org.hibernate.cfg.SettingsFactory.createRegionFactory(SettingsFactory.java:423) ~[hibernate-core-3.6.2.Final.jar:3.6.2.Final]
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:280) ~[hibernate-core-3.6.2.Final.jar:3.6.2.Final]
at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2836) ~[hibernate-core-3.6.2.Final.jar:3.6.2.Final]
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2832) ~[hibernate-core-3.6.2.Final.jar:3.6.2.Final]
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1843) ~[hibernate-core-3.6.2.Final.jar:3.6.2.Final]
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:903) ~[hibernate-entitymanager-3.6.2.Final.jar:3.6.2.Final]
... 45 common frames omitted
Caused by: java.lang.ClassNotFoundException: net.sf.ehcache.hibernate.EhCacheRegionFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:202) ~[na:1.6.0_22]
at java.security.AccessController.doPrivileged(Native Method) ~[na:1.6.0_22]
at java.net.URLClassLoader.findClass(URLClassLoader.java:190) ~[na:1.6.0_22]
at java.lang.ClassLoader.loadClass(ClassLoader.java:307) ~[na:1.6.0_22]
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) ~[na:1.6.0_22]
at java.lang.ClassLoader.loadClass(ClassLoader.java:248) ~[na:1.6.0_22]
at java.lang.Class.forName0(Native Method) ~[na:1.6.0_22]
at java.lang.Class.forName(Class.java:169) ~[na:1.6.0_22]
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:192) ~[hibernate-core-3.6.2.Final.jar:3.6.2.Final]
at org.hibernate.cfg.SettingsFactory.createRegionFactory(SettingsFactory.java:409) ~[hibernate-core-3.6.2.Final.jar:3.6.2.Final]
... 50 common frames omitted
Я ясно вижу, что и ehcache, и hibernate находятся в моем дереве зависимостей maven; Что-нибудь особенное, что нужно сделать в конфигурации приложения Spring?