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?
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?
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.
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...
SCDJWS 5.0, SCBCD 5.0, SCWCD 5.0, SCJP 5.0
You know it is dark times when the trees riot. I think this tiny ad is their leader: