my dog learned polymorphism*
The moose likes EJB and other Java EE Technologies and the fly likes BMP question,Help me! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "BMP question,Help me!" Watch "BMP question,Help me!" New topic
Author

BMP question,Help me!

flaying ma
Greenhorn

Joined: Jan 16, 2002
Posts: 4
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
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
"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.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
    
    5
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


Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at http://www.kyle-brown.com/ for other WebSphere information.
flaying ma
Greenhorn

Joined: Jan 16, 2002
Posts: 4
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!
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
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.
flaying ma
Greenhorn

Joined: Jan 16, 2002
Posts: 4
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();
}
.........
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16019
    
  20

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 ]

Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: BMP question,Help me!