can I use the same EntityManager (same PersistenceContext) to persist a few EntityBean of different types? for example:

@Stateful
public class BankServiceBean implements BankService {
@PersistenceContext(unitName="BankService")
private EntityManager em;
private Customer cust;
private Account acc = new Account();

public void addCustomer(int custId, String firstName,String lastName) { 
cust = new Customer(); 
cust.setld(custld); 
cust.setFirstName(firstName); 
cust.setLastName(lastName); 
em.persist(cust);
em.persist(acc);

}
1

There are 1 best solutions below

1
On

Yes, this is possible, only if your different Entity beans are using same dataSource property.

Since your EntityManager has 'transaction manager' property, which in turn has datasource property.