Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7021757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:29:32+00:00 2026-05-27T23:29:32+00:00

This is the thing … I have my Maven web project based on spring3.0

  • 0

This is the thing … I have my Maven web project based on spring3.0 and i wanted to use hibernate+jpa for my DA … but when i try to use the entityManager objet i just get a nullPointerException … here is the code:

@Repository
@Component
public class DAOPersonImp implements DAOPerson{

@PersistenceContext
private EntityManager entityManager;
@Override
public Person getById(int id) {
    // TODO Auto-generated method stub
    return entityManager.find(Person.class, id);
}

@Override
@Transactional
public List<Person> getAll() {
    Query query = entityManager.createQuery("SELECT * FROM  PERSON");
    List<Person> persons = null;
    persons = query.getResultList();
    return persons;
}

when i try to create the query objet i get the error.

This is my applicationContext.xml

<?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
http://www.springframework.org/schema/tx  http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="persistenceUnitName" value="PersistUnit" />
    <property name="jpaVendorAdapter">
        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
            <property name="database" value="MYSQL" />
            <property name="showSql" value="true" />
        </bean>
    </property>
</bean>

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>

And the error!

GRAVE: Servlet.service() for servlet [dispatchermaven] in context with path [/OneX-1] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause
java.lang.NullPointerException
    at com.divux.onex.daoImp.DAOPersonImp.getAll(DAOPersonImp.java:45)
    at com.divux.onex.logic.FriendListLogic.getEntrys(FriendListLogic.java:23)
    at com.divux.onex.controller.FriendListController.getEntrys(FriendListController.java:25)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
    at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:426)
    at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:414)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:563)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:399)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:317)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:204)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:182)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:311)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:679)

Dont know how much info whould you need but i will give u guys whatever you need!

Thanks a lot! Srry for my terrible english …

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T23:29:33+00:00Added an answer on May 27, 2026 at 11:29 pm

    PersistenceContex not injecting entitymanager .So you are getting NullPointerException makesure persistence.xml in correct place and its unit name is correct .I also post a sample configuration so you can configure applicationContex accordingly.

        <!-- Prints used SQL to stdout -->
    
        <property name="showSql" value="${hibernate.show.sql}"/>
    
        <!-- Generates tables. -->
    
        <property name="generateDdl" value="${hibernate.generate.ddl}"/>
    
        <property name="databasePlatform" value="${postgres.hibernate.database.platform}"/>
    
    </bean>
    
    
    
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
    
          destroy-method="close">
    
        <property name="driverClass" value="${postgres.datasource.driver.class}"/>
    
        <property name="jdbcUrl" value="${postgres.datasource.jdbc.url}"/>
    
        <property name="user" value="${postgres.datasource.username}"/>
    
        <property name="password" value="${postgres.datasourse.password}"/>
    
        <property name="minPoolSize" value="1"/>
    
        <property name="acquireIncrement" value="1"/>
    
        <property name="maxPoolSize" value="3"/>
    
    </bean>
    
    
    
    <tx:annotation-driven transaction-manager="postgres.transactionManager"/>
    
    
    
    <bean id="postgres.transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    
        <property name="entityManagerFactory" ref="entityManagerFactory"/>
    
        <property name="dataSource" ref="dataSource"/>
    
    </bean>
    
    
    
    <bean id="entityManagerFactory"
    
          class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    
        <property name="dataSource" ref="dataSource"/>
    
        <property name="jpaVendorAdapter" ref="jpaAdapter"/>
    
        <property name="persistenceUnitManager" ref="persistenceUnitManager"/>
    
        <property name="persistenceUnitName" value="PersistenceUnit"></property>
    
    </bean>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think I couldnt do this thing, but I try to ask (maybe :)).
First thing I know this is repeated question but I don't have problem in
This is a self-explanatory question: Why does this thing bubble into my try catch's
I have this thing working mostly. What I don't get is, if I have
I have this thing that i need to do and some advices will be
I've been looking around for a solution to this thing but I haven't found
This thing is driving me nuts. I have a UserControl that is called WebUserControl.
I have been seeing this thing for months and years and i really wanna
I have this thing on my webpage... I guess it could be called a
i have a this thing in my views,py def status_change(request): if request.method == POST:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.