Hello everyone,
I have an entity bean(Account)  which is throwing an exception and
this is not being caught by the session bean. The sequence is that

one insert
entity update
another insert.

all should go as one unit of transaction or not at all.

We try to update the entity bean with an illegal value so that it
fails and the whole transaction rolls back.

The code is as below

PreparedStatement prepFirst = con.prepareStatement("insert into sabra values(?,?)");
prepFirst.setString(1,id);
prepFirst.setString(2,name);
prepFirst.executeUpdate();
prepFirst.close();
try
{
     InitialContext context = new InitialContext();
     Object objref = context.lookup("java:comp/env/ejb/AccountService");
     AccountHome home =
               (AccountHome)PortableRemoteObject.narrow(objref,
                                      AccountHome.class);
     Account account = home.findByPrimaryKey("123");
     account.credit(12345.00);
     System.out.println("here after credit");

     System.out.println("here again");
     PreparedStatement prepTwo = con.prepareStatement("insert into sabra values(?,?)");
     prepTwo.setString(1,idFail);
     prepTwo.setString(2,nameFail);

     prepTwo.executeUpdate();

     System.out.println("here again again");
     prepTwo.close();
     con.close();
     }
     catch(Exception e)
     {
          System.out.println("here babe exception");
          throw new EJBException("failed babe");
     }

The sequence in which actions happen

the sql insert one happens
the entity does not throw an exception yet
the sql insert two happens

and then
the ejbstore of the entity is called which only then has the error happening and the
EJBException is thrown, but there is nothing to catch it then.

o/p is like this

here after credit
here again
here again again

and then the exception thrown by the entity although this should have happened before 
'here after credit'

although the sequence should have been

only the exception thrown by the entity bean and then nothing else.....

Can anyone help out?

Kind Regards
Aby Philip



Reply via email to