简体   繁体   中英

state for one or more table in DB with EJB3

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 im 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;
}
}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM