spring mvc - Not able to wire entityManager with applicationContext bean -


i facing problem wire entity manager bean present in application context. whenever operation gives nullpointerexception.

this applicationcontext.xml file

<?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://www.springframework.org/schema/beans"        xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"        xmlns:context="http://www.springframework.org/schema/context"        xmlns:tx="http://www.springframework.org/schema/tx"        xsi:schemalocation="http://www.springframework.org/schema/beans         http://www.springframework.org/schema/beans/spring-beans-3.0.xsd         http://www.springframework.org/schema/context         http://www.springframework.org/schema/context/spring-context-3.0.xsd">      <context:component-scan base-package="com.ajit.retail"/>      <bean id="datasource" class="org.springframework.jdbc.datasource.drivermanagerdatasource">         <property name="driverclassname" value="org.postgresql.driver"/>         <property name="url" value="jdbc:postgresql://localhost/retail"/>         <property name="username" value="retail_user"/>         <property name="password" value="password"/>     </bean>      <bean id="entitymanagerone" class="org.springframework.orm.jpa.localcontainerentitymanagerfactorybean">         <property name="datasource" ref="datasource"/>         <property name="jpavendoradapter">             <bean class="org.springframework.orm.jpa.vendor.hibernatejpavendoradapter">                 <property name="showsql" value="true"/>                 <property name="databaseplatform" value="org.hibernate.dialect.postgresql82dialect"/>             </bean>         </property>     </bean>      <bean id="transactionmanager" class="org.springframework.orm.jpa.jpatransactionmanager">         <property name="entitymanagerfactory" ref="entitymanagerone"/>     </bean>      <tx:annotation-driven transaction-manager="transactionmanager"/>      </beans> 

this java file in creating entity manager

import javax.persistence.entitymanager; import javax.persistence.persistencecontext;  public class abstractrepository {      @persistencecontext     entitymanager entitymanager; } 

so whenever use entity manager gives null pointer exception please help!

your entity manager bean called enetitymanagerone, variable called entitymanager. maybe renamme bean in xml file:

<bean id="entitymanager" class="org.springframework.orm.jpa.localcontainerentitymanagerfactorybean"> 

another solution forgot following bean declarations:

for support transaction:

<tx:annotation-driven/> 

the support parsing jpa annotations:

<bean class="org.springframework.orm.jpa.support.persistenceannotationbeanpostprocessor"/> 

Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -