Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
PavanPL KalyanK
Ranch Hand
Posts: 212
  • Mark post as helpful
  • send pies
  • 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.
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • 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.
 
Anurag Blore
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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.
 
Hong Anderson
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
  • 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?
 
RaviNada Kiran
Ranch Hand
Posts: 528
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • 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?


 
Raffael Bechara Rameh
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic