-1

hy all, we suppose we have many entity A, B, C ,D when i call ejb bean for save new entity or update entity, i would like found a mode for verify if not another managed Bean thread has save a new entity A or B or C or D or has update one or mode for verify if a table is modified when i m in transaction because when i like save new Entity A has a many field integer depend for haw match specific entity B and c and d is saved in DB

@Stateless
public class EntityABean implements EntityARemote, EntityALocal {

@Resource
 private SessionContext context;

@EJB
private DaoEntity daoEntityEjb;

public void doSomthing(Object param1, Object param2 ...) {
try {
 //dosomthing
}
catch(Excepyion ex) {
context.rollback();
throw ex;
}
}
sghaier ali
  • 433
  • 2
  • 15

1 Answers1

0

Your question is not very clear but from what I can make out is that you probably need automatic Optimistic Concurrency control mechanism of JPA. You need to annotate your version column as explained here and the rest is taken care of by the underlying JPA compliant provider. For more details you can take a look at another SO answer here.

You can further control the way JPA manages locking on a versioned entity by specifying a lock mode. You do this through the lock() method of the EntityManager class. Here is the method signature:

public void lock(Object entity, LockModeType lockMode);

For more explanation take a look here

Community
  • 1
  • 1
Shailendra
  • 8,874
  • 2
  • 28
  • 37
  • i know that, my problem i like found mode observer o another for i call it for i can have information if during my transaction there is not another thread has update or save new entity. Another solution is : all metode call one metode syncro for i can garanted all entity is not modified or is new one is saved when i m in the metode – sghaier ali Jun 12 '15 at 15:07
  • the solution is in EJB3.1 when i can use session @singleton how i guaranted the access is syncro for all methode in this beans – sghaier ali Jun 15 '15 at 16:16