EntityManager的remove()是否导致实体脱管?非事务范围实例调用该方法呢?
1. Does EntityManager.remove() cause an entity to become detached?
Absolutely. When you call EntityManager.remove(someEntity), the entity is marked for deletion, and it immediately becomes detached from the persistence context. Keep in mind that the actual database deletion operation executes when the transaction commits (for transaction-scoped EntityManagers), but the entity transitions to a detached state right after the remove() call is made.
2. Does calling EntityManager.remove(someEntity) on a non-transaction-scoped EntityManager cause the entity to become detached?
Yes, it does. Even for extended (non-transaction-scoped) container-managed EntityManagers, invoking remove() will detach the target entity. The core semantic of the remove() method includes removing the entity from the persistence context and marking it for deletion—this detachment behavior isn't dependent on whether the EntityManager is transaction-scoped or not. That said, without an active transaction for an extended EntityManager, the delete operation won't be persisted to the database until you explicitly begin and commit a transaction to sync the persistence context.
According to the JSR-317 specification:
If using a transaction-scoped container-managed EntityManager, transaction commit results in detached entities (see Section 3.3); operations such as transaction rollback (see Section 3.3.2), detaching an entity from the persistence context, clearing the persistence context, closing the EntityManager, and serializing an entity also result in detached entities.
内容的提问来源于stack exchange,提问作者osama yaccoub

