database doesn't seem to be updated

Hi!

I have a web application that works like this:

1. A client goes to an html page and fills a form with registration data.

2. The form is submitted to a servlet (servlet1) in Application A.

3. The servlet invokes a methd on a session bean with the registration data.

4. The session bean saves the registration data in a database and sends it (by HTTP) to another application (Application B). The message sent has an id to identify the registration.

5. Application B precesses the data.

6. Application B sends the response data to Application A (again, by HTTP) to servlet2.

7. When Application A receives the response and searches the database for a registration with the received id, it doesn't find it!!!!

If I invoke servlet2 manually, the registration is found.

If I do it just after I add the registration to the database it is also found.

But not when Application B invokes servlet2.

All data is saved in the database using CMP entity beans.

Can anyone help me?

Any doubts, please ask!

Nuno Geraldes

[1112 byte] By [nhpg] at [2007-11-25 10:44:56]
# 1

Right after Application B invokes servlet2, Do a manual select * from the database and see if the registration is found.

If the registration is still there then I guess the problem is that when Application B is invoking servlet 2 is looking at a different database.

Thanks,

sherry Barkodar

sherry barkodar at 2007-7-1 21:39:16 > top of Java-index,Development Tools,Java Tools...
# 2
I don't think that could be the problem.I use a static method to access the database and, as I said previously, if I invoke that method right after I update the database, the registration is found.Don't you have any more clues on what may be happening?Nuno
nhpg at 2007-7-1 21:39:16 > top of Java-index,Development Tools,Java Tools...
# 3
Try running in debug mode and watching the HTTP requests and responses. The problem might be that you are setting the variables to the wrong scope level.
jetsons at 2007-7-1 21:39:16 > top of Java-index,Development Tools,Java Tools...
# 4

Well... here's what I did to work it out:

After I updated the database, I invoked the findAll() method and it started working fine!

But I still think I shouldn't be forced to do it, so, if anyone knows another way to solve the problem, I'm open to suggestions.

Thanks for the tip, sherry

Nuno Geraldes

nhpg at 2007-7-1 21:39:16 > top of Java-index,Development Tools,Java Tools...
# 5
I am wondering if the transaction used by servlet B is different and dependending on the database transaction properties cannot see the pending transaction.
cbwebster at 2007-7-1 21:39:16 > top of Java-index,Development Tools,Java Tools...
# 6

> I am wondering if the transaction used by servlet B

> is different and dependending on the database

> transaction properties cannot see the pending

> transaction.

Well, I must say that my code has no reference to any transactions. I use container-managed transactions. Should I change this?

nhpg at 2007-7-1 21:39:16 > top of Java-index,Development Tools,Java Tools...
# 7
What is the transaction attribute (Required, Requires New). The transaction will likely need to be committed before the read from the second servlet (as this won't be in the same transaction).
cbwebster at 2007-7-1 21:39:16 > top of Java-index,Development Tools,Java Tools...
# 8
I don't know where I can change the transaction attribute. I always wondered where I could do that. Does anyone know?
nhpg at 2007-7-1 21:39:16 > top of Java-index,Development Tools,Java Tools...
# 9

The session bean communicates with the database in the registration method (I think). The transaction attributes for this method can be set using the module level property sheet. Find the method and change the transaction attribute. You can try to seperate the registration and the notification so that the registration can be committed before the notification occurs.

cbwebster at 2007-7-1 21:39:16 > top of Java-index,Development Tools,Java Tools...
# 10
I'm sorry, but I don't know where the module level property sheet is. Could you please tell me?
nhpg at 2007-7-1 21:39:16 > top of Java-index,Development Tools,Java Tools...
# 11
Right clicking on the ejb module allows editing of the deployment descriptor and server specific deployment properties using a property sheet.
cbwebster at 2007-7-1 21:39:16 > top of Java-index,Development Tools,Java Tools...
# 12

I found out what's happening.

In step 4, when App A sends the message to App B, it sends it to a servlet. The servlet invokes a method on a session bean. The http connection between App A and App B only gets closed after the session bean method returns.

So, as the session bean method in App B sends a message to App A through servlet 2, when servlet 2 executes, App A still hasn't commited the transaction (because it will only commit after the http connection is closed).

I was wondering if I could solve this using threads.

Another question: instead of invoking servlet 2, could the session bean method in App B return the message (it was supposed to send to servlet 2) and put the message in the response so App A could receive it?

nhpg at 2007-7-1 21:39:16 > top of Java-index,Development Tools,Java Tools...
# 13

I would not recommend starting a new thread in the application server as the resource allocation is generally handled by the server. I can't provide you with a definitive answer without knowing more about the application you are building but if you need to do something asynchronously you may want to consider using message driven beans.

cbwebster at 2007-7-1 21:39:16 > top of Java-index,Development Tools,Java Tools...
# 14
OK!I will do that.Thanks for the help, Chris!
nhpg at 2007-7-1 21:39:16 > top of Java-index,Development Tools,Java Tools...