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 How can i rollback the Transactions when using with CMT in EJB3.0 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "How can i rollback the Transactions when using with CMT in EJB3.0" Watch "How can i rollback the Transactions when using with CMT in EJB3.0" New topic
Author

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

PavanPL KalyanK
Ranch Hand

Joined: Feb 28, 2009
Posts: 212

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.
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10142
    
165

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.


[My Blog] [JavaRanch Journal]
Anurag Blore
Ranch Hand

Joined: Jan 15, 2003
Posts: 74
Get the context of the bean and use this method context.setRollbackOnly();

For example in MDB



Thanks,
Anurag
SCJP 1.2 & 1.5, PMP
PavanPL KalyanK
Ranch Hand

Joined: Feb 28, 2009
Posts: 212
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

Joined: Jan 15, 2003
Posts: 74
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

Joined: Feb 28, 2009
Posts: 212
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.
Hong Anderson
Ranch Hand

Joined: Jul 05, 2005
Posts: 1936
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?


SCJA 1.0, SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCJP 5.0, SCEA 5, SCBCD 5; OCUP - Fundamental, Intermediate and Advanced; IBM Certified Solution Designer - OOAD, vUML 2; SpringSource Certified Spring Professional
RaviNada Kiran
Ranch Hand

Joined: Jan 30, 2009
Posts: 528
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.


If you want something you never had do something which you had never done
PavanPL KalyanK
Ranch Hand

Joined: Feb 28, 2009
Posts: 212
Hi Ravi,

Thanks for extending my question.

Can anybody please tell me how could you do this

Thanks in advance.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

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?



JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Raffael Bechara Rameh
Greenhorn

Joined: Dec 28, 2012
Posts: 1
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.
 
GeeCON Prague 2014
 
subject: How can i rollback the Transactions when using with CMT in EJB3.0