This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
True, I should be able to catch the remoteException, But the problem is that ....
Session Bean is running in "Requires New"
If i change this to "Not Required" , I can catch the Remote Exception.
But I cant do it because ...
I have to insert into one table (using entity) ... Then log, that the insert is successfull in other table...
Any of the above two fails I need to rollback ...
I guess , the problem is EJBException marks transaction for rollback... and when the session bean receives another exception... It again trys to mark the transaction for rollback ... This results in error .....
Just a guess,
Thanks and regards, Shailesh
Joined: Sep 29, 2002
Set the transaction attribute of the entity bean's method to Required. This will solve your problem as both updates will run in the same transaction.
Joined: Aug 12, 2005
My Entity does have "Requires" set,
My Exact problem is that, the database has a "unique" constraint set on it, So its failure is revealed only when ejbstore is called.
When this cosntraint is viaolated i throw an EJBException("Unique cosntraint violated").
But The remote Exception when caught , always gives me transactionRollBackException, i tried remoteExeption.detail as well.
So, the problems are :
1. Catch the RemoteException when SessionBean is running "requires new" and entity "requires" (works in WSAD 5.0, but i dont know why,it doesnt on WSAD 5.1.2)
2. Catch the Message that i set in EJBException. ( i want to see the message , because there are two unique constraints and i need to diffrenciate between the same)
hi shailesh The ejbStore methods is called by the container and not by you. The problem occurs here, when ever you update any variables in your entity bean the container calls that beans ejbStore method to persists itself with the database. so as you throw an exception in this method the container will assume that the transaction is been interupted and will automatically roll back the transaction and throws a TransactionRollBackException to intimate the client that there is a problem with that transaction and so it has been rolledback. That's why you get a TransactionRolledBackException instead of EJBException which you threw inside the ejbStore() method.
Veshnu<br />SCBCD<br />SCWCD<br />SCJP
Joined: Aug 12, 2005
Hasnt anyone found the need to catch the exception in ejbStore and communicate to client the exact reason of failure?
If i can catch only remote exception, and the e.detail.getMessage or e.getMessage all return me only "Transaction roll back exception" .
How can i inform the client that the error is because of 1. business condition failure (in my case, unique constraint failure, i need to say to client " your record already exist" ) or
2. some other failure (unable to get connection to db, i need to say to client "please try after some time").
The only workarround I see to use direct sqls instead of entity's setter methods, But then; what is the use of the entity bean?
Does this mean that when entities are being used, we are not using any constriants on the database?
As per EJB Spec, if you are trying to store two records with same key in a database it throws a DuplicateKeyException. if you want to check it yourself with your own sql, try throwing an application exception rather than remote exception from your code inside ejbStore.