Forums Register Login

BMP question,Help me!

+Pie Number of slices to send: Send
I make a BMP with jb6 from a CMP,The CMP is work well in Weblogic61,But the BMP is error:
Start server side stack trace:
java.rmi.RemoteException: EJB Exception:; nested exception is:
java.lang.NullPointerException
java.lang.NullPointerException
at testbmp2.CabinBean.ejbCreate(CabinBean.java:31)
at testbmp2.CabinBean_12m8qx_Impl.ejbCreate(CabinBean_12m8qx_Impl.java:172)
at java.lang.reflect.Method.invoke(Native Method)
at weblogic.ejb20.manager.DBManager.create(DBManager.java:492)
at weblogic.ejb20.manager.DBManager.remoteCreate(DBManager.java:462)
at weblogic.ejb20.internal.EntityEJBHome.create(EntityEJBHome.java:190)
at testbmp2.CabinBean_12m8qx_HomeImpl.create(CabinBean_12m8qx_HomeImpl.java:75)
at testbmp2.CabinBean_12m8qx_HomeImpl_WLSkel.invoke(Unknown Source)
at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:298)
at weblogic.rmi.cluster.ReplicaAwareServerRef.invoke(ReplicaAwareServerRef.java:93)
at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:267)
at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest.java:22)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:139)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
End server side stack trace
+Pie Number of slices to send: Send
"flaying"
Please note that JavaRanch has a naming standard that requires the use of your real first name - space - your real last name. Please change your display name to reflect this. Thanks.
+Pie Number of slices to send: Send
Yes, so what is happening at line 31 of your BMP cabin bean? Insert some System.out.println() statements or use a debugger and find out what object is null...
Kyle
+Pie Number of slices to send: Send
But at line31,is a testClient load a remote Bean's mothed!
Some one tell me there is't have a remote mothed,So the error is "NullPointerException"
Why! help me! Thanks a lots!
+Pie Number of slices to send: Send
 

Originally posted by flaying ma:
But at line31,is a testClient load a remote Bean's mothed!
Some one tell me there is't have a remote mothed,So the error is "NullPointerException"
Why! help me! Thanks a lots!


Show us the code around that error. Perhaps we can see if you are accessing the bean correctly.
+Pie Number of slices to send: Send
package testbmp2;
import javax.ejb.*;
import java.util.*;
import java.rmi.*;
import java.sql.*;
import javax.sql.*;
import javax.naming.*;
public class CabinBean implements EntityBean {
public EntityContext entityContext;
public Integer ID;
public String Name;
//next is ejbCreate **********************************************************
public Integer ejbCreate(java.lang.Integer id) throws CreateException {
this.ID = id;
Connection conn = null;
PreparedStatement ps = null;
try
{
try
{
conn = getConnection();
}
catch(Exception e)
{
e.printStackTrace();
}
ps = conn.prepareStatement("insert into Cabin (id, name) values (?, ?)");
ps.setInt(1, id.intValue());
ps.setString(2, "");
if(ps.executeUpdate() != 1)
{
throw new CreateException("Filed to add Cabin to database!");
}
return id;
}
catch(SQLException e)
{
throw new EJBException(e);
}
finally
{
try
{
if(ps != null)
{
ps.close();
}
if(conn != null)
{
conn.close();
}
}
catch(SQLException e)
{
e.printStackTrace();
}
}
}
........................
package testbmp2;
import javax.ejb.*;
import java.util.*;
import java.rmi.*;
public interface CabinRemote extends javax.ejb.EJBObject {
public void setId(java.lang.Integer id) throws RemoteException;
public java.lang.Integer getId() throws RemoteException;
public void setName(java.lang.String name) throws RemoteException;
public java.lang.String getName() throws RemoteException;
}
..................................
package testbmp2;
import javax.ejb.*;
import java.util.*;
import java.rmi.*;

public interface CabinRemoteHome extends javax.ejb.EJBHome {
public CabinRemote create(java.lang.Integer id) throws CreateException, RemoteException;
public CabinRemote findByPrimaryKey(java.lang.Integer id) throws FinderException,RemoteException;
}
....................................
package testbmp2;
import javax.naming.*;
import java.util.Properties;
import javax.rmi.PortableRemoteObject;
public class CabinTestClient1 {
private static final String ERROR_NULL_REMOTE = "Remote interface reference is null. It must be created by calling one of the Home interface methods first.";
private static final int MAX_OUTPUT_LINE_LENGTH = 100;
private boolean logging = true;
private CabinRemoteHome cabinRemoteHome = null;
private CabinRemote cabinRemote = null;
//CabinTestClient1 cabinTestClient1 = new CabinTestClient1();
//Construct the EJB test client
public CabinTestClient1() {
long startTime = 0;
if (logging) {
log("Initializing bean access.");
startTime = System.currentTimeMillis();
}
try {
//get naming context
Context ctx = getInitialContext();
//look up jndi name
Object ref = ctx.lookup("CabinRemote");
//cast to Home interface
cabinRemoteHome = (CabinRemoteHome) PortableRemoteObject.narrow(ref, CabinRemoteHome.class);
if (logging) {
long endTime = System.currentTimeMillis();
log("Succeeded initializing bean access.");
log("Execution time: " + (endTime - startTime) + " ms.");
}
try
{
java.lang.Integer id = new Integer("112");
log("The id ="+id);
//cabinRemote = cabinRemoteHome.findByPrimaryKey(id);
CabinRemote cabinRemote = cabinRemoteHome.create(id);
cabinRemote.setName("runFrank");
}
catch(Exception e)
{
log("@The error is:"+e);
e.printStackTrace();
}
.........
+Pie Number of slices to send: Send
By my reckoning "conn" is still null when you invoke prepareStatement(). Possibly related is the fact that although you catch exceptions attempting to initialize conn, you then go ahead and attempt to use it anyway. If conn didn't initialize, you really ought to just throw an EJBCreateException, since you can't do anything further anyway.
[ March 11, 2002: Message edited by: Tim Holloway ]
Goodbye moon men. Hello tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1221 times.
Similar Threads
IllegalStateException
Bean Managed Entity Bean problem
Entity bean - Connection busy ?!
BMP ejbRemove() problem
Bean Managed Entity Bean problem
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 15:47:55.