相关疑难解决方法(0)

如何管理我的实体对象,以便将其删除?

这不起作用 - 我总是抛出IllegalArgumentException,并提出"尝试合并分离并再次尝试删除"的建议.

@PersistenceContext private EntityManager   em;
@Resource           private UserTransaction utx;
public void delete(EN entity) {
    if (entity == null) return;   // null-safe
    EN target = entity;
    try {
        if (!em.contains(entity)) {
            System.out.println("delete() entity not managed: " + entity);
            utx.begin();
            target = em.merge(entity);
            utx.commit();
            System.out.print("delete() this entity should now be managed: " + em.contains(target));
        }
        utx.begin();
        em.remove(target);
        utx.commit();
    } catch (RollbackException ex) {
        Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
    } catch (HeuristicMixedException ex) {
        Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
    } catch (HeuristicRollbackException ex) {
        Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, …
Run Code Online (Sandbox Code Playgroud)

jpa jpa-2.0

1
推荐指数
1
解决办法
8003
查看次数

标签 统计

jpa ×1

jpa-2.0 ×1