• 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
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

doubt at respect TransactionRequiredException

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
You know it is dark times when the trees riot. I think this tiny ad is their leader:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic