Hi,
I am trying to find a row using the primary key from the database
using a CMP entity bean.
I was successful in deploying the bean,creating the row using the bean.I
am using a Custom Primary key class which implements the serializable
interface,hashcode,equals and toString functions.
my Client code is as follows:-
public class CabinClient {
public static void main(String [] args){
try {
Context jndiContext = getInitialContext();
System.out.println("initial context :"+ jndiContext);
Object ref = jndiContext.lookup("Cabin");
System.out.println("Reference :"+ref);
CabinHome home = (CabinHome)
PortableRemoteObject.narrow(ref,CabinHome.class);
try{
Cabin cab = home.create(1);
cab.setName("Master Suite");
cab.setDeckLevel(2);
cab.setShip(1);
cab.setBedCount(3);
}
catch(javax.ejb.DuplicateKeyException dke)
{ System.out.println("Row already exists."); }
CabinPK pk = new CabinPK(1);
Cabin cab2 = home.findByPrimaryKey(pk);<======== line no.42
as show in the exception
System.out.println(cab2.getName());
System.out.println(cab2.getDeckLevel());
System.out.println(cab2.getShip());
System.out.println(cab2.getBedCount());
}
catch(java.rmi.RemoteException re)
{ re.printStackTrace(); }
catch(javax.naming.NamingException ne)
{ ne.printStackTrace(); }
catch(javax.ejb.CreateException ce)
{ ce.printStackTrace(); }
catch(javax.ejb.FinderException fe)
{ fe.printStackTrace(); }
}
public static Context getInitialContext() throws
javax.naming.NamingException
{
System.setProperty("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
System.setProperty("java.naming.provider.url","localhost:1099");
Context ctx = new javax.naming.InitialContext();
return ctx;
}
}
After creating the row I am getting an exception while doing
findByPrimary key.
---------------Client side exception------------------
D:\java\ejb\cabin>java com.ebd.ejb.CabinClient
initial context :javax.naming.InitialContext@5efa1a
Reference :Cabin home
Primary Key :1
Exception in thread "main" java.lang.NullPointerException: Id may not be
null
at
sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Stream
RemoteCall.java:245)
at
sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:
220)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:122)
at
org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker_Stub.invokeHom
e(Unknown Source)
at
org.jboss.ejb.plugins.jrmp.interfaces.HomeProxy.invoke(HomeProxy.java
:79)
at $Proxy0.findByPrimaryKey(Unknown Source)
at com.ebd.ejb.CabinClient.main(CabinClient.java:42)
--------------Server Side Exception---------------
[Container factory] Deploying:file:/D:/EDEV/java/ejb/cabin/Cabin.jar
[Container factory] Deploying Cabin
[JAWS] Initializing JAWS plugin for Cabin
[JAWS] Remove:DELETE FROM Cabin WHERE id=?
[JAWS] Drop:DROP TABLE Cabin
[JAWS] Create table:CREATE TABLE Cabin (id INTEGER,level INTEGER,name
VARCHAR(25
6),bc INTEGER,ship INTEGER)
[JAWS] Insert:INSERT INTO Cabin (id,level,name,bc,ship) VALUES
(?,?,?,?,?)
[JAWS] Select:SELECT id,level,name,bc,ship FROM Cabin WHERE id=?
[JAWS] Exists:SELECT COUNT(*) AS Total FROM Cabin WHERE id=?
[Container factory] Bound Cabin to Cabin
[JAWS] Table Cabin exists
[Container factory] Deployed application:
file:/D:/EDEV/java/ejb/cabin/Cabin.jar
[Default] org.jboss.tm.TxManager@1de498
[JAWS] SQL:SELECT COUNT(*) AS Total FROM Cabin WHERE id=?
[Cabin] Set parameter:1
[JAWS] Object count:1
at
org.jboss.ejb.plugins.jrmp.interfaces.EntityProxy.<init>(EntityProxy.
java:62)
at
org.jboss.ejb.plugins.jrmp13.interfaces.EntityProxy.<init>(EntityProx
y.java:24)
at
org.jboss.ejb.plugins.jrmp13.server.JRMPContainerInvoker.getEntityEJB
Object(JRMPContainerInvoker.java:64)
at org.jboss.ejb.EntityContainer.find(EntityContainer.java:365)
at java.lang.reflect.Method.invoke(Native Method)
at
org.jboss.ejb.EntityContainer$ContainerInterceptor.invokeHome(EntityC
ontainer.java:478)
at
org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invokeHome(Ent
itySynchronizationInterceptor.java:147)
at
org.jboss.ejb.plugins.EntityInstanceInterceptor.invokeHome(EntityInst
anceInterceptor.java:77)
at
org.jboss.ejb.plugins.TxInterceptor.invokeHome(TxInterceptor.java:84)
at
org.jboss.ejb.plugins.SecurityInterceptor.invokeHome(SecurityIntercep
tor.java:75)
at
org.jboss.ejb.plugins.LogInterceptor.invokeHome(LogInterceptor.java:1
01)
at
org.jboss.ejb.EntityContainer.invokeHome(EntityContainer.java:306)
at
org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker.invokeHome(JRM
PContainerInvoker.java:166)
at
org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker.invokeHome(JRM
PContainerInvoker.java:130)
at java.lang.reflect.Method.invoke(Native Method)
at
sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:241)
at sun.rmi.transport.Transport$1.run(Transport.java:142)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:139)
at
sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:4
43)
at
sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport
.java:643)
at java.lang.Thread.run(Thread.java:484)
at
org.jboss.ejb.plugins.jrmp.interfaces.EntityProxy.<init>(EntityProxy.
java:62)
at
org.jboss.ejb.plugins.jrmp13.interfaces.EntityProxy.<init>(EntityProx
y.java:24)
at
org.jboss.ejb.plugins.jrmp13.server.JRMPContainerInvoker.getEntityEJB
Object(JRMPContainerInvoker.java:64)
at org.jboss.ejb.EntityContainer.find(EntityContainer.java:365)
at java.lang.reflect.Method.invoke(Native Method)
at
org.jboss.ejb.EntityContainer$ContainerInterceptor.invokeHome(EntityC
ontainer.java:478)
at
org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invokeHome(Ent
itySynchronizationInterceptor.java:147)
at
org.jboss.ejb.plugins.EntityInstanceInterceptor.invokeHome(EntityInst
anceInterceptor.java:77)
at
org.jboss.ejb.plugins.TxInterceptor.invokeHome(TxInterceptor.java:84)
at
org.jboss.ejb.plugins.SecurityInterceptor.invokeHome(SecurityIntercep
tor.java:75)
at
org.jboss.ejb.plugins.LogInterceptor.invokeHome(LogInterceptor.java:1
01)
at
org.jboss.ejb.EntityContainer.invokeHome(EntityContainer.java:306)
at
org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker.invokeHome(JRM
PContainerInvoker.java:166)
at
org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker.invokeHome(JRM
PContainerInvoker.java:130)
at java.lang.reflect.Method.invoke(Native Method)
at
sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:241)
at sun.rmi.transport.Transport$1.run(Transport.java:142)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:139)
at
sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:4
43)
at
sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport
.java:643)
at java.lang.Thread.run(Thread.java:484)
[Cabin] java.lang.NullPointerException: Id may not be null
[Default] java.lang.NullPointerException: Id may not be null
I am stuck at this point.Any help will be appreciated.
PKD
--
--------------------------------------------------------------
To subscribe: [EMAIL PROTECTED]
To unsubscribe: [EMAIL PROTECTED]
Problems?: [EMAIL PROTECTED]