1 Reply Latest reply on Jul 9, 2004 5:43 AM by Alexey Loubyansky

    Query after session bean record returns wrong results

    Norton Newbie

      Hi,

      I have a server application that is given a user id, verifies that it exists in one table, records an event in a second table, and returns an event count back to the requester. My problem is that the count being returned is not including the last event recorded.

      Here are the details:

      The application consists of an Entity bean to do the verification (using a findByXXX()), a session bean to do the event recording, and a straight prepared statement query to get the event count. Here's the psuedo code:

      getUserIdFromClient();
      valid = userhome.findByUserId();
      eventRemote.record(userEvent);
      count = getCountFromEventTable();

      The EntityBean uses a "Required" trans-attribute while the event session bean uses a "RequiresNew" trans-attribute. I was coached years ago that it would be better to use a session bean when just doing inserts because the overhead of an entity bean would be unnecessary. But it appears to me that some commit isn't happening before the getCountFromEventTable() method is being called, so the count is always off by one. As I write this, I seem to recall discussions about commit options. I don't know a lot about commit options, so all of mine are at the JBoss default.

      Is my assessment of the problem correct? If so, how do I correct it? I would rather not fool with the commit options. Is there something in the code I can do to guarantee the event insert be committed so I get the right count returned? Or is there something else causing the problem?

      Thanx in advance for your help.

      Norton