File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes Getting TransactionRolledbackLocalException when record deletion process failed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Getting TransactionRolledbackLocalException when record deletion process failed" Watch "Getting TransactionRolledbackLocalException when record deletion process failed" New topic
Author

Getting TransactionRolledbackLocalException when record deletion process failed

Gihan Pandigamage
Ranch Hand

Joined: Aug 23, 2009
Posts: 60
Hello Friends,
In my application I'm trying to delete a record from a database. When the deletion process failed, following code executes.

So when deletion process failed I have been getting following error instead of the mentioned error message




I tried so many times but couldn't figure out why above error occurs. Please help me.
Volodymyr Levytskyi
Ranch Hand

Joined: Mar 29, 2012
Posts: 505
    
    1

This line:

is generated by this in your catch block:

The problem is that you are trying to remove column that references column 'APPLICANTCODE' in table "dbo.APPLICANTJOBSPEC". You should remove at first column that is
referenced that is 'APPLICANTCODE'!!! But if 'APPLICANTCODE' is primary key then I can't give you any advice how to remove this primary key. I tried it one evening and I
didn't succeed.


True person is moral, false is right!
Gihan Pandigamage
Ranch Hand

Joined: Aug 23, 2009
Posts: 60
Yes It's correct. But the thing is when I throw "throw new EJBException(ex.toString()); " it gives the following error. Couldn't figure out why this is happening ??

Volodymyr Levytskyi
Ranch Hand

Joined: Mar 29, 2012
Posts: 505
    
    1

I found about TransactionRolledbackLocalException this in Internet:


Maybe it is better to roll back current transaction before throwing new EJBException(ex.toString) in catch block, but I am not sure.
Gihan Pandigamage
Ranch Hand

Joined: Aug 23, 2009
Posts: 60
but the thing is I'm doing transaction roll back process in one of my previous method.
When executing "rowsAffected = stmt.executeUpdate(); " line it gives SQLServerException then throw "throw new EJBException(ex.toString());" line


When "throw new EJBException(ex.toString());" executed then this exception is handle by the following code under the "InvocationTargetException" catch block.
Then it throws a "throw new Exception(e1.getCause());" exception to another method(deleteApplicant(ApplicantDTO applicantDTO)) as follows




from the following method transaction rolled back.

Volodymyr Levytskyi
Ranch Hand

Joined: Mar 29, 2012
Posts: 505
    
    1

Hello!

Sorry if I tell something wrong!

You wrote that you rolled back transaction in one of your previous methods. You have your problems in method public void ejbRemove() { ... } when you execute

That is when line throw new EJBException(ex.toString()); executes this exception is thrown

Fact that you rolled back transaction in previous method doesn't mean that method public void ejbRemove() { ... } runs out of transaction.
Probably you haven't specified @TransactionAttribute(TransactionAttributeType.SUPPORTS) on method public void ejbRemove() { ... } thus default transaction type is used
which is TransactionAttributeType.REQUIRED which means if there is no transaction NEW transaction will be created. It is created because of default TransactionAttributeType.REQUIRED.
It means that any method in your application not annotated by @TransactionAttribute(TransactionAttributeType.SUPPORTS) is invoked within new( if there is no existent )
or existent (if any) transaction.

Maybe you should try to annotate your public void ejbRemove() which causes problems with @TransactionAttribute(TransactionAttributeType.SUPPORTS) but I am not sure
because I am real beginner.
@TransactionAttribute(TransactionAttributeType.SUPPORTS) means that method runs within current transaction (if any) or no transaction at all (if there is no current).
Ranganathan Kaliyur Mannar
Bartender

Joined: Oct 16, 2003
Posts: 1096
    
  10

Volodymyr Levytskyi wrote:Probably you haven't specified @TransactionAttribute(TransactionAttributeType.SUPPORTS) on method public void ejbRemove() { ... }


No, I think the user is using BMT. The user starts a transaction manually in the deleteApplicant method. Plus, I think the user is using EJB 2.x.

Gihan,
Please specify the EJB version you are using. Also, can you check the ejb-jar.xml to find out what the transaction type is specified?


Ranga.
SCJP 1.4, OCMJEA/SCEA 5.0.
Gihan Pandigamage
Ranch Hand

Joined: Aug 23, 2009
Posts: 60


<transaction-type>Bean</transaction-type> and the EJB version is 2.1
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting TransactionRolledbackLocalException when record deletion process failed