Everything you have tested is in accordance with the specification. The save context is retained (and the objects remain attached) as long as the transaction exists. Thus, in the extended persistence and transaction NOT_SUPPORTED objects retrieved when the search method is invoked are filtered out. -Also, if your Customer object has a lazy relationship and you are trying to access them, then it is very likely that you will get an exception at runtime.
Now, why is the merge method ok ?. First, remember that merge returns a managed entity and binds the client to a persistence context.
Secondly, you have an EXTENDED persistent context, so it will not update the database until you call the annotated @Remove method. When this call arrives, you are likely to receive a TransactionRequiredException .
EDIT 1 --------------------------------------------- --- --------------------------------
According to your comments:
find not required in the transaction, although if you need a managed object, it must be one.
The paragraph refers to the life cycle (section 3.3), in this case it tries to explain that at the end of the method for the bean transaction area, the objects will be detached, but in the case of an extended EM, the objects will remain attached.
There are two insightful paragraphs:
When an EM with an extended persistence context is used, the hold, delete, merge, and update operations can be invoked regardless of whether the transaction is active. The effects of these operations will be tied to the database when the extended save context is credited to the transaction and the transaction commits.
The save context is closed by the container when the @Remove method of a session with a bean state ends (or an instance of a session with a bean state).
- It looks like the method that you first omit in the question using
@TransactionAttribute(REQUIRES_NEW) is the place where the merge is successful. That is why you have no exception.
EDIT 2 --------------------------------------------- --- --------------------------------
After some testing, GF4 has an error, and> https://java.net/jira/browse/GLASSFISH-20968 was reported
EDIT 3 --------------------------------------------- --- ---------------------------------
May 20/2014: the error was noted as: must be fixed for Glassfish 4.0.1.
source share