• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Getting TransactionRolledbackLocalException when record deletion process failed

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 514
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Gihan Pandigamage
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ??

 
Bin Smith
Ranch Hand
Posts: 514
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Bin Smith
Ranch Hand
Posts: 514
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).
 
Bartender
Posts: 1104
10
Netbeans IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
Gihan Pandigamage
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


<transaction-type>Bean</transaction-type> and the EJB version is 2.1
 
reply
    Bookmark Topic Watch Topic
  • New Topic