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
Roger Chung-Wee
Ranch Hand
Joined: Sep 29, 2002
Posts: 1683
posted
0
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.
shailesh Kumar
Greenhorn
Joined: Aug 12, 2005
Posts: 8
posted
0
Hi,
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)
There aren't may rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.
In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.
Thanks! Dave
shailesh Kumar
Greenhorn
Joined: Aug 12, 2005
Posts: 8
posted
0
Hi,
To catch the exception 1. we had to create an intermediate method with "No transaction" and from there call all methods with "requires"
2. But we always get "transaction roll back exception" , we are unable to retrieve a custom message set in EJBException
Regards, Shailesh
Roger Chung-Wee
Ranch Hand
Joined: Sep 29, 2002
Posts: 1683
posted
0
The container is not obliged to encapsulate EJBException in RemoteException. What you can do is invoke setRollbackOnly and then throw a custom application exception (instead of throwing EJBException).
Veshnu Ramakrishnan
Ranch Hand
Joined: Sep 27, 2005
Posts: 44
posted
0
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
shailesh Kumar
Greenhorn
Joined: Aug 12, 2005
Posts: 8
posted
0
Hi,
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.