Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Unable to catch StaleObjectStateException. EJB exception doesn't wrap it.  RSS feed

 
Ahmed Basheer
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I am developing an EJB3 application in Jboss 5 with a db connector to MySQL.
I am trying to prevent simultaneous writes of two or more transactions on the same entities by using a @Version annotated field inside the affected session bean.
If I test it by forcing two transactions to simulataneously read the same entities and then write them I get a StaleObjectException and one transaction rolls back. That's fine!
But, I am unable to catch this exception with a try{...} catch(Exception e)... block around the method that starts the transaction. The EJBTransaction doesn't wrap the StaleObjectStateException. I did investigate the State track and in EJBTransactionfail exception I could NOTsee StaleObjectStateException wrapped? I don't want to propagate this exception back to the client I just want to restart the transaction.

Any suggestion? I appreciate.
Basheer
 
Leonardo Carreira
Ranch Hand
Posts: 494
Eclipse IDE Java Postgres Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ahmed Basheer..

May i know your implementation of transaction code?..
which one do you use? global or local transaction?..
and then are you implementing CMT or BMT?..

How about if you implement code like this below (BMT) :
assume that we want to update an item..



i'm not teaching you, i just learning with you together..
Please correct me if i'm wrong..

Thanks in advance..
 
Ahmed Basheer
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using local transactions and CMT. Perheps the code you gave will catch the stale exception. But I can,t use this code as I am using CMT. It seems transaction manager "Arjuna" in jboss is contributing to this prob. But it is such a basic thing I can't imagine that stale exception is not wrapped in ejb transaction fail exception. Thank you for you response. I am expecting some one like Jai Kiran , who spearheads the ejb3 on jboss dev, to address this issue.

Thanks
Ahmed
 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post the entire exception stacktrace?

But, I am unable to catch this exception with a try{...} catch(Exception e)... block around the method that starts the transaction.


By the way remember that when using entitymanager to do persistence operations, the actual queries are fired on transaction commit (i.e. after the control has moved out of the method). So something like this may not always work:

The catch block would not be able to catch the exception thrown on tx commit because the control has already moved out of the method.

One of the ways to get around this, is to manually do a flush on the entitymanager so that the queries are fired immidiately:



 
Ahmed Basheer
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jai,

I will post the full stackTrace shortly. But it is EJBTransactionRolledbackException wrapping RoleBackException and the then wrapping throwable.

I use container managed transaction. @Transaction Required tag. The client of the bean has a try catch.
client code:

try
{
mybean.update(obj)
}
catch(StaleObjectStateException)
{
// no staleobjectstateexception is thrown.
}
catch(Exception e}
{
//even if I unwind the exception no staleobjectstateexception exists.
}
----------------------

mybean code

@Transaction(REQUIRED)
public void update(Obj) throws exception
{
}
I clearly see in the server that StaleObjectStateException is thrown but Client of the bean doesn't see it and hence doesn't retry the transaction.

I will post the stack trace shortly.I can't use EntityManager as I use CMT allowing the EJB contain to open close session and Transaction.

Thanks,
Bashir
 
Ahmed Basheer
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jai,

The exception stack trace is at http://img8.imageshack.us/img8/8634/exceptionb.jpgClearly StaleObjectStateException is not wrapped.Let me know if you need more info


Thanks,
Basheer

 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Would have been easier to parse the exception stacktrace had you posted it as text here, instead of the image

From what i see in that image, it appears to be because of this

Here's the JIRA for that https://jira.jboss.org/jira/browse/JBTM-575.
 
Ahmed Basheer
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
THank you for being very responsive. It seems that jboss5.1 has this bug.but how would programatically retry the transaction if you get staleobjectstate exception in cmt environment, when the exception doesn,t tell you root cause of the problem. Is there a work around. I agree that logs does show the cause that is meaningless though.

hmm...
Basheer
 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have a application which reproduces this issue with the root cause of the exception being eaten up, then please open a JIRA here https://jira.jboss.org/jira/browse/JBAS. Please attach your application to that JIRA. I know there's already a JIRA for this in the JBTM project, but i guess it would make sense to have it reported against the AS too.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!