File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes nullPointerException on entity manager methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "nullPointerException on entity manager methods" Watch "nullPointerException on entity manager methods" New topic
Author

nullPointerException on entity manager methods

Martin Frisone
Greenhorn

Joined: Nov 05, 2007
Posts: 7
Hi,
I'm working on a desktop application that reads data from a database using persistence manager Toplink and the netbeans IDE.
I have set:

  • The persistence unit (persistence.xml)
  • @PersistenceContext annotation
  • "EntityManager em" class
  • the entity clases from the DB


  • the problem comes when I try to execute any of the entity manager methods, such as persist() or find(). It always throws a NullPointerException so I'd like to know where could be my problem. Any idea will help.
    Thanks in advance
    Freddy Wong
    Ranch Hand

    Joined: Sep 11, 2006
    Posts: 959

    Can you provide us with the code and the stacktrace?


    SCJP 5.0, SCWCD 1.4, SCBCD 1.3, SCDJWS 1.4
    My Blog
    Martin Frisone
    Greenhorn

    Joined: Nov 05, 2007
    Posts: 7
    sure....

    Persistence Unit "minuto1PU"


    Entity class "Cliente"


    Main class "Minuto1"


    Martin Frisone
    Greenhorn

    Joined: Nov 05, 2007
    Posts: 7
    and forgot the stacktrace

    Freddy Wong
    Ranch Hand

    Joined: Sep 11, 2006
    Posts: 959

    Do you run this application in an EJB container? @PersistenceContext can only be used if you use EJB. If you use pure JPA, you need to create the EntityManager by yourself, e.g.

    Martin Frisone
    Greenhorn

    Joined: Nov 05, 2007
    Posts: 7
    Oh! yes, I see my mistake now... I'm not using an EJB containter just a desktop application, that's why the Container Managed Persistence won't work.

    I've tried the Application Managed Persistence and it worked. Problem Solved, thanks a lot
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: nullPointerException on entity manager methods
     
    Similar Threads
    Lazy loading exception in presentation layer, what's the nicest way to avoid them?
    find and getReference methods
    Audit Log
    JTA Transaction Mangement
    Resource Local Transactions