简体   繁体   English

使用 EJB3 对 DB 中的一个或多个表进行状态

[英]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总而言之,当我调用 ejb bean 来保存新实体或更新实体时,我们假设我们有许多实体 A、B、C、D,我想找到一种模式来验证是否另一个托管 Bean 线程已保存新实体 A 或B 或 C 或 D 或已更新一个或模式以验证当我在事务中时是否修改了表,因为当我喜欢保存新实体 A 时,有许多字段整数取决于 haw 匹配特定实体 B 和 c 和 d 保存在数据库中

@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.您的问题不是很清楚,但据我所知,您可能需要 JPA 的自动乐观并发控制机制。 You need to annotate your version column as explained here and the rest is taken care of by the underlying JPA compliant provider.您需要按照此处的说明对版本列进行注释,其余部分由符合 JPA 的底层提供程序处理。 For more details you can take a look at another SO answer here .有关更多详细信息,您可以在此处查看另一个 SO 答案。

You can further control the way JPA manages locking on a versioned entity by specifying a lock mode.您可以通过指定锁定模式来进一步控制 JPA 管理对版本化实体的锁定的方式。 You do this through the lock() method of the EntityManager class.您可以通过 EntityManager 类的 lock() 方法执行此操作。 Here is the method signature:这是方法签名:

public void lock(Object entity, LockModeType lockMode);

For more explanation take a look here更多解释请看这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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