| 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" classthe 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
|
 |
 |
|
|
subject: nullPointerException on entity manager methods
|
|
|