-
Book Overview & Buying
-
Table Of Contents
EJB 3 Developer Guide
By :
In this section we look at some more EntityManager methods.
The remove() method flags an entity for removal from the database. Note that the entity must be a managed entity. The removal need not take place immediately. Removal occurs whenever the EntityManager decides to synchronize, or flush, the persistence context with the database. Typically this occurs when a transaction is committed. The code below shows a BankServiceBean method, removeCustomer(), which would be invoked in order to remove a Customer entity.
public void removeCustomer(Customer cust) {
Customer mergedCust = em.merge(cust);
em.remove(mergedCust);
}
Note that the method first merges an entity to ensure it is managed before removing it.
The contains() method is used to check whether an entity is managed in the current persistence context. It returns a boolean which is set to true if the entity is managed, otherwise it set to false. For example:
if (em.contains(cust)) {
System.out...
Change the font size
Change margin width
Change background colour