Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

BMP ejbRemove() problem

 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When my client calls ejbRemove the following error occurs :
(serverside output)
ejbActivate() was called
ejbLoad() was called
ejbStore() was called
Unable to load person from db:java.sql.SQLException: java.lang.NullPointerExcept
ion
ejbActivate() was called
ejbLoad() was called
ejbStore() was called
Unable to load person from db:java.sql.SQLException: java.lang.NullPointerExcept
ion
ejbActivate() was called
ejbLoad() was called
ejbStore() was called
Unable to load person from db:java.sql.SQLException: java.lang.NullPointerExcept
ion
ejbActivate() was called
ejbLoad() was called
ejbRemove() was called
Unable to remove person with id 123
from db(connection +true):java.sql.SQLException: java.lang.NullPointerExcepti
on
java.sql.SQLException: Verletzung der PRIMARY KEY-Einschr�nkung 'PK_Person'. Ein
doppelter Schl�ssel kann in das persons-Objekt nicht eingef�gt werden. Severity
14, State 1, Procedure 'MAXWELL null', Line 1
at weblogic.jdbc.mssqlserver4.TdsStatement.processWarning(TdsStatement.j
ava:1229)
at weblogic.jdbc.mssqlserver4.TdsStatement.parseMsWarning(TdsStatement.j
ava:1140)
at weblogic.jdbc.mssqlserver4.TdsStatement.getMoreResults(TdsStatement.j
ava:798)
at weblogic.jdbc.mssqlserver4.TdsStatement.execute(TdsStatement.java:214
)
at weblogic.jdbc.mssqlserver4.TdsStatement.executeUpdate(TdsStatement.ja
va:97)
at weblogic.jdbc.mssqlserver4.TdsStatement.executeUpdate(TdsStatement.ja
va:1516)
at weblogic.jdbc.pool.Statement.executeUpdate(Statement.java:293)
at weblogic.jdbc.rmi.internal.PreparedStatementImpl.executeUpdate(Prepar
edStatementImpl.java:66)
at weblogic.jdbc.rmi.SerialPreparedStatement.executeUpdate(SerialPrepare
dStatement.java:57)
at PersonBMPBean.ejbCreate(PersonBMPBean.java:67)
at PersonBMPBean_9iber2_Impl.ejbCreate(PersonBMPBean_9iber2_Impl.java:17
7)
at java.lang.reflect.Method.invoke(Native Method)
at weblogic.ejb20.manager.DBManager.create(DBManager.java:519)
at weblogic.ejb20.manager.DBManager.remoteCreate(DBManager.java:489)
at weblogic.ejb20.internal.EntityEJBHome.create(EntityEJBHome.java:190)
at PersonBMPBean_9iber2_HomeImpl.create(PersonBMPBean_9iber2_HomeImpl.ja
va:77)
at PersonBMPBean_9iber2_HomeImpl_WLSkel.invoke(Unknown Source)
at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:305)
at weblogic.rmi.cluster.ReplicaAwareServerRef.invoke(ReplicaAwareServerR
ef.java:93)
at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.jav
a:274)
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)
**************************
(clientside output):
C:\stage\bmp>java PersonClient
time for creating InitialContext in milli sec : 4367
time for JNDI lookup in milli sec : 290
Time for finding a single entry: 401
Time for finding a collection of entries: 20
3 entries found for Max
123
555
789
Time for deleting an entry: 40
Received an unexpected exception weblogic.ejb20.RuntimeCheckerException: Your BMP ejbCreate should not be returning null.
Start server side stack trace:
weblogic.ejb20.RuntimeCheckerException: Your BMP ejbCreate should not be returning null.
at weblogic.ejb20.manager.DBManager.create(DBManager.java:539)
at weblogic.ejb20.manager.DBManager.remoteCreate(DBManager.java:489)
at weblogic.ejb20.internal.EntityEJBHome.create(EntityEJBHome.java:190)
at PersonBMPBean_9iber2_HomeImpl.create(PersonBMPBean_9iber2_HomeImpl.java:77)
at PersonBMPBean_9iber2_HomeImpl_WLSkel.invoke(Unknown Source)
at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:305)
at weblogic.rmi.cluster.ReplicaAwareServerRef.invoke(ReplicaAwareServerRef.java:93)
at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:274)
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
while using the PersonEJB.
Exception in thread "main" weblogic.ejb20.RuntimeCheckerException: Your BMP ejbCreate should not be returning null.
Start server side stack trace:
weblogic.ejb20.RuntimeCheckerException: Your BMP ejbCreate should not be returning null.
at weblogic.ejb20.manager.DBManager.create(DBManager.java:539)
at weblogic.ejb20.manager.DBManager.remoteCreate(DBManager.java:489)
at weblogic.ejb20.internal.EntityEJBHome.create(EntityEJBHome.java:190)
at PersonBMPBean_9iber2_HomeImpl.create(PersonBMPBean_9iber2_HomeImpl.java:77)
at PersonBMPBean_9iber2_HomeImpl_WLSkel.invoke(Unknown Source)
at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:305)
at weblogic.rmi.cluster.ReplicaAwareServerRef.invoke(ReplicaAwareServerRef.java:93)
at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:274)
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
****************************
The RunTimeChecker Exception seems to be a result of the failed ejbRemove(), since in my client I remove the bean and insert it in next statement.
Here it the ejbRemove() Method:
public void ejbRemove() {
System.out.println("ejbRemove() was called");
if(con==null) con=getConnection();
PreparedStatement ps = null;
try {
ps = con.prepareStatement(
"delete from persons where id = ?");
ps.setString(1, id);
if(ps.executeUpdate() != 1) {
System.out.println("Unable to del entity bean!");
}
}catch (SQLException e) {
System.out.println(
"Unable to remove person with id "+id+" from db(connection +"(con!=null)+"):"+e.toString());
}try {
con.close();
} catch(Exception e) {}
}
*************
I am sure that there is a trivial error in this method, but I fail to find it.
Oh, and the entity with key '123' does exist in the database named test and in the table named persons.
This NullPointerException is strange, since id and con are not null. What can be null then ?
 
Maximilian Trenks
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oh, and here is the code of the ejbStore() method that also fails (overlooked it):

[ February 28, 2003: Message edited by: Thomas Paul ]
 
Author
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It looks from the client-side error message like your ejbCreate method returns null. While this is SOP for CMP beans, a BMP bean is supposed to return a valid PK object.
Also, you occasionally get weird NPEs when the equals() or hashCode() methods in your PK class can't handle null values in the PK. Don't ask why, just make sure they work even in the presence of null PK values.
 
Maximilian Trenks
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanx arron for your reply, but I dont know what you mean ;-)
what is an NPE ?
my key class is string, what should i change there?

thanx,
max
 
Maximilian Trenks
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oh what i forgot to say is that i tried to run the ejbStore() method on a client.
the datasource was accquired the same way like on the bean. i got a securityException there telling me that the user guest doesnt have a certain permission, which i dont remember by heart (was something with r i guess, reserve maybe ??).
this occurs on all update and insert statements (i found out with the sql profiler tool that no update oder insert statement is ever propagated to the database). do i have to give a permission to actually change the database ?
 
Ranch Hand
Posts: 2713
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what is an NPE ?
NullPointerException
 
Chris Mathews
Ranch Hand
Posts: 2713
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by max t:
oh what i forgot to say is that i tried to run the ejbStore() method on a client.


The client should never directly call ejbStore() or any lifecycle method. These are managed by the Container.
 
Aaron Mulder
Author
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If your key class is a String, you don't have to do anythign to fix it. But how about your ejbCreate method? Does it ever return null? It shouldn't, for a BMP bean.
 
Maximilian Trenks
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
actually it does return null when an SQLException occurs.
but in what way shall I change it ?
return an empty string ?
 
Chris Mathews
Ranch Hand
Posts: 2713
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by max t:
actually it does return null when an SQLException occurs.
but in what way shall I change it ?
return an empty string ?


When an exception occurs that your ejb cannot handle then you should throw an exception. In the case of a create then the appropriate exception would be javax.ejb.CreateException. In other cases it could be a simple javax.ejb.EjbException or a predefined Application Exception. There is no use in covering up the error, which is what you are doing now. Obviously the client can not continue on without first addressing this issue.
BTW, this is true of object design in general, not just EJB. Exception Handling in Java follows the Chain of Responsibility Pattern. The exception(or a wrapped version) should continue on until it gets to a point where it can be handled appropriately.
[ February 27, 2003: Message edited by: Chris Mathews ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic