Title: RE: Possible Bug wrt Servlets and creating/finding entities

I would like to apologise to the Orion team. This is probably one of the stupidest mistakes I've made in a while.

Thanks to Victor for making me look at my code more closely ;)

The problem was that the servlet calls a private member method to create the entity and takes it's return value (an Object) as the primary key of the newly created entity. However, I had made a mistake when creating the method and it was returning the entity itself and not its primary key. A REAL ClassCastException ;)

Thanks,
Gordon

-----Original Message-----
From: Victor A. Salaman [mailto:[EMAIL PROTECTED]]
Sent: Monday, 08 May 2000 19:08
To: 'Gordon Tyler'
Subject: RE: Possible Bug wrt Servlets and creating/finding entities


Hi Gordon:
 
We can't help you much without a snippet of the code in question...
 
-- Victor
-----Original Message-----
From: Gordon Tyler [mailto:[EMAIL PROTECTED]]
Sent: Monday, May 08, 2000 12:15 PM
To: Orion-Interest
Subject: Possible Bug wrt Servlets and creating/finding entities


Hi,
Sorry, this is fairly long...
The scenario is this: An Entity bean called InboundMessage, and a servlet called InboundServlet. The InboundMessage entity is used to store the XML of incoming messages according to a primary key extracted from the XML.

The InboundServlet processes an HTTP POST (by implementing the doPost method of HttpServlet) and reads a string containing XML from the request into a String. The InboundServlet then gets InboundMessageHome calls create() to create a new entity with the primary key and the XML string (the XML string is stored in a CLOB column).

Now, in the real application, the servlet would then start a new Thread, giving it the primary key of the entity that was just created, and the Thread then gets InboundMessageHome and calls findByPrimaryKey to get the entity and works on it while the Servlet returns a success code to the client.

However, to simplify matters while testing, I incorporated the Thread's processing code into the servlet's doPost method directly after the entity has been created.

But what happens is that after the servlet has successfully created the entity and it calls InboundMessageHome.findByPrimaryKey, it gets a ClassCastException like so:

java.lang.ClassCastException: EntityBeanWrapper0
        at com.ast.test.InboundServlet.doPost(InboundServlet.java:57)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java)
        at com.evermind.server.http.de.o0(JAX)
        at com.evermind.server.http.de.forward(JAX)
        at com.evermind.server.http.dl.cd(JAX)
        at com.evermind.util.e.run(JAX)
I'm assuming that this is when Orion's implementation of the home interface is casting the instance of EntityBeanWrapper0 to the InboundMessage remote interface when it returns from the findByPrimaryKey method.

I then stopped the server, modified the servlet so that it doesn't create the entity but rather uses a hard-coded primary key of a row that already exists in the database in the call to InboundMessageHome.findByPrimaryKey and reran the server. Now it finds the entity successfully without the ClassCastException.

I tried a further permutation of this. I took the code of the servlet that creates and then finds the entity and put that into a standalone client. The standalone client creates and immediately finds the newly created entity without a problem.

So the ClassCastException only occurrs in a servlet when finding an entity that has just been created.
Any suggestions? Is this a bug in Orion?
Thanks,
Gordon
--- Codito, ergo sum - "I code, therefore I am" ---
Gordon Tyler <[EMAIL PROTECTED]>
Abraxas IT Services - Component Based Devleopment
Tel: +27-(0)21-6803412
PGP key available on request or finger [EMAIL PROTECTED]
"Official IT Partner to the Two Oceans Marathon"
http://www.twooceansmarathon.org.za

Reply via email to