• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How can i rollback the Transactions when using with CMT in EJB3.0

 
Ranch Hand
Posts: 212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

My requirement is to rollback a Transaction which acts with (REQUIRED) Transaction Attribute .

How can i tell the container to rollback a transaction when using with CMT in EJB3.0

Any help appreciated.
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

PavanPL KalyanK wrote:


How can i tell the container to rollback a transaction when using with CMT in EJB3.0


The container will rollback the transaction if there is any system exception thrown during the transaction.
 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Get the context of the bean and use this method context.setRollbackOnly();

For example in MDB


 
PavanPL KalyanK
Ranch Hand
Posts: 212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jaikiran Pai wrote:

PavanPL KalyanK wrote:


How can i tell the container to rollback a transaction when using with CMT in EJB3.0


The container will rollback the transaction if there is any system exception thrown during the transaction.



But i want to do it for ApplicationException also.

I need tospecify to the Container that if @ApplicationException(rollback=true).

Any ideas?
 
Anurag Blore
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does ApplicationException means the Exception which you have defined in your application?

Please check this post on Java Ranch may be useful.

ranch link
 
PavanPL KalyanK
Ranch Hand
Posts: 212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It was really a nice link.THanks for sharing.

ApplicationException means the Exception which you have defined in your application? (This is for my Business Requirement )

For example RecordNotFoundException .

Now i want to tell my container if RecordNotFoundException (ApplicationException) comes rollback it.

How do i register this RecordNotFoundException in the XML file?

Any help.
 
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

PavanPL KalyanK wrote:
But i want to do it for ApplicationException also.

I need tospecify to the Container that if @ApplicationException(rollback=true).

Any ideas?


Just do it, what is the problem?
 
Ranch Hand
Posts: 528
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Kengkaj ,

Do you know what the Author is referring to ??

He can have many ApplicationExceptions like DataNotFoundException ResourceNotFoundException ----etc.

Now how to say the container that these belong to ApplicationException and Not SystemException and how to rollback or commit when these occur.
 
PavanPL KalyanK
Ranch Hand
Posts: 212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ravi,

Thanks for extending my question.

Can anybody please tell me how could you do this

Thanks in advance.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

RaviNada Kiran wrote:Hello Kengkaj ,

Do you know what the Author is referring to ??

He can have many ApplicationExceptions like DataNotFoundException ResourceNotFoundException ----etc.

Now how to say the container that these belong to ApplicationException and Not SystemException and how to rollback or commit when these occur.



Not sure I understand. Why would you commit when an exception is thrown?

I'm also not sure what having many ApplicationExceptions is an issue either, why can't these just be annotated accordingly?


 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can do it:

@ApplicationException(rollback=true)
public class MyBusinessException extends RuntimeException {
(...)
}

And then:
public class MyException2 extends MyBusinessException {
(...)
}

Then:
public class MyException3 extends MyBusinessException {
(...)
}

And so on....

@ApplicationException(rollback=true) will be propagated to MyException2, MyException3, .... etc...

Hope this helps.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic