A
Aravind
Hello,
I am new to java EE - Im using Java5 bundled with Netbeans and java App
server and the Toplink Db.
I created entity classes for a table in db and a stateless session bean
for the enity classes. (Everything was automatically done in Netbeans).
Now I have a app client which calls the session bean (remote
interface).
The problem is that whenever the bean tries to acess the database, I
get a NullPointerException.
If I simply return a "Hello" message from the bean to the appClient it
works - that is there is no problem for my app client to access to
session bean. But when the bean tries to contact the db using the
entitymanager.find() method, then the entity manager always gives the
exception.
Am I missing something here?
Thanks,
--Aravind.
The code:
package ejb;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
@Stateless
public class BankloginFacade implements BankloginFacadeLocal,
BankloginFacadeRemote {
@PersistenceContext
private EntityManager em;
public BankloginFacade() {
}
public void create(Banklogin banklogin) {
em.persist(banklogin);
}
public void edit(Banklogin banklogin) {
em.merge(banklogin);
}
public void destroy(Banklogin banklogin) {
em.merge(banklogin);
em.remove(banklogin);
}
public Banklogin find(Object pk) {
//***********ERROR RAISED HERE**********
return (Banklogin) em.find(Banklogin.class, pk);
}
public List findAll() {
return em.createQuery("select object(o) from Banklogin as
o").getResultList();
}
Error stack trace:
WARNING: ACC003: Application threw an exception.
java.lang.NullPointerException
at ejb.BankloginFacade.find(BankloginFacade.java:46)
at bankapp.Main.main(Main.java:35)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at
com.sun.enterprise.util.Utility.invokeApplicationMain(Utility.java:232)
at
com.sun.enterprise.appclient.MainWithModuleSupport.<init>(MainWithModuleSupport.java:329)
at com.sun.enterprise.appclient.Main.main(Main.java:180)
Exception in thread "main" java.lang.RuntimeException:
java.lang.reflect.InvocationTargetException
at
com.sun.enterprise.appclient.MainWithModuleSupport.<init>(MainWithModuleSupport.java:340)
at com.sun.enterprise.appclient.Main.main(Main.java:180)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at
com.sun.enterprise.util.Utility.invokeApplicationMain(Utility.java:232)
at
com.sun.enterprise.appclient.MainWithModuleSupport.<init>(MainWithModuleSupport.java:329)
... 1 more
Caused by: java.lang.NullPointerException
at ejb.BankloginFacade.find(BankloginFacade.java:46)
at bankapp.Main.main(Main.java:35)
... 7 more
Java Result: 1
I am new to java EE - Im using Java5 bundled with Netbeans and java App
server and the Toplink Db.
I created entity classes for a table in db and a stateless session bean
for the enity classes. (Everything was automatically done in Netbeans).
Now I have a app client which calls the session bean (remote
interface).
The problem is that whenever the bean tries to acess the database, I
get a NullPointerException.
If I simply return a "Hello" message from the bean to the appClient it
works - that is there is no problem for my app client to access to
session bean. But when the bean tries to contact the db using the
entitymanager.find() method, then the entity manager always gives the
exception.
Am I missing something here?
Thanks,
--Aravind.
The code:
package ejb;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
@Stateless
public class BankloginFacade implements BankloginFacadeLocal,
BankloginFacadeRemote {
@PersistenceContext
private EntityManager em;
public BankloginFacade() {
}
public void create(Banklogin banklogin) {
em.persist(banklogin);
}
public void edit(Banklogin banklogin) {
em.merge(banklogin);
}
public void destroy(Banklogin banklogin) {
em.merge(banklogin);
em.remove(banklogin);
}
public Banklogin find(Object pk) {
//***********ERROR RAISED HERE**********
return (Banklogin) em.find(Banklogin.class, pk);
}
public List findAll() {
return em.createQuery("select object(o) from Banklogin as
o").getResultList();
}
Error stack trace:
WARNING: ACC003: Application threw an exception.
java.lang.NullPointerException
at ejb.BankloginFacade.find(BankloginFacade.java:46)
at bankapp.Main.main(Main.java:35)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at
com.sun.enterprise.util.Utility.invokeApplicationMain(Utility.java:232)
at
com.sun.enterprise.appclient.MainWithModuleSupport.<init>(MainWithModuleSupport.java:329)
at com.sun.enterprise.appclient.Main.main(Main.java:180)
Exception in thread "main" java.lang.RuntimeException:
java.lang.reflect.InvocationTargetException
at
com.sun.enterprise.appclient.MainWithModuleSupport.<init>(MainWithModuleSupport.java:340)
at com.sun.enterprise.appclient.Main.main(Main.java:180)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at
com.sun.enterprise.util.Utility.invokeApplicationMain(Utility.java:232)
at
com.sun.enterprise.appclient.MainWithModuleSupport.<init>(MainWithModuleSupport.java:329)
... 1 more
Caused by: java.lang.NullPointerException
at ejb.BankloginFacade.find(BankloginFacade.java:46)
at bankapp.Main.main(Main.java:35)
... 7 more
Java Result: 1