Wednesday 17 February 2016

How to resolve Spring+Hibernate repository BeanCreationException related to persistence


If you see any such error as like below

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'xxxxxViewRepository': Invocation of init method failed; nested exception is java.lang.NullPointerException

check whether you have the correct persistentunit declared as below, the value of the property persistentUnitName should match with persistent-unit name which is declared in persistence.xml

 <bean id="entityManagerFactoryBean" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
   <property name="dataSource" ref="dataSource"/>
<property name="persistenceXmlLocation" value="classpath:/META-INF/persistence.xml"/>  
   <property name="persistenceUnitName" value="xxxxxPU"/>
   <property name="jpaVendorAdapter" ref="jpaVendorAdapter"/>
 </bean>

Persistence.xml is the one below

<persistence-unit name="xxxxxPU">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />
<property name="hibernate.show_sql" value="false" />
<property name="hibernate.format_sql" value="false" />
<property name="hibernate.generate_statistics" value="false" />
<property name="hibernate.use_sql_comments" value="false" /> -->
<property name="net.sf.ehcache.configurationResourceName" value="META-INF/ehcache.xml" />
<property name="hibernate.cache.use_query_cache" value="false" />
<property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory" />
</properties>
</persistence-unit>

No comments:

Post a Comment