The container should rollback the transaction for you.

When it comes to update/insert/delete, I would go for entity beans XOR
SSB/JDBC.

You can not do business rule validation in ejbStore, although it is
tempting. The reason is that you cannot throw an application exception. So
you better put validation type of business rules in the actual business
methods of the entity bean (if at all in an entity bean).

/Johan

-----Original Message-----
From: A mailing list for Enterprise JavaBeans development
[mailto:[EMAIL PROTECTED]]On Behalf Of Thomas T. Alex
Sent: den 11 juli 2001 16:48
To: [EMAIL PROTECTED]
Subject: Exception thrown by BMP not being caught by Session

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
Thomas T. Alex

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to