This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doubt at respect TransactionRequiredException

 
Rafael Rocha
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in question enthuware simulator, exactly in custom test with 20 question, in question seven, exist one case about call method on the EntityManager, that remove, persist, refresh and merger, for example. ok

my doubt about that exception, in this case, in response for simulator:
---
The container throws the TransactionRequiredException if a transaction-scoped persistence context is used, and the EntityManager persist, remove, merge, or refresh method is invoked when no transaction is active.
---
otherwise, if i have been used transaction "extended" for persistence context, what occurs?
 
Rafael Rocha
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
other question, is that in question is not mentioned used session bean for local and remote, in this case, how i know exactly exception?

below this question
----
A bean method has just called entityManager.remove(student); where student is a valid entity. Assuming that the bean uses transaction scoped persistence manager and the call is made when no transaction is active, what will be the outcome?
 
krishna bulusu
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can I assume the following code for your above question:

In the above code, whenever the method deleteEmployee is called, it won't participate in the transaction. Would it throw exception if we call it?
I don't think so. It works normally. If emp object is attached(I am assuming as in your question, it is specifies that the object is a valid entity) then it will be removes from the database.
 
Vinay Nath
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey Rafael,

that is actually an interesting question.

The reason why this requirement of calling remove when a transaction exist is because in case of transaction scoped persistent context, the life of persistent context is tightly coupled with that of transaction. A persistent context gets created at the start of a method when transaction also is created. And when transaction commits persistent context is also closed.

So it doesnt make sense to call em.remove() when no transaction is there as it is useless without a transaction.

In case of "extended", an extended context is seperated from transaction so you can call em.remove() without a transaction and it will be okay.

hope that helps...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic