2

我想删除一个对象会出现以下错误:

javax.ejb.EJBException:java.lang.IllegalArgumentException:删除分离的实例。

我的代码:

public void remover(MensagemContato param) {
    PersistenciaMensagemContato pParam = new PersistenciaMensagemContato();     
    pParam.delete(param);
    pParam.close();
}

有没有人在使用hibernate简单删除对象时遇到过这个问题?

谢谢!

黛博拉

4

3 回答 3

0

您不能删除不是来自数据库的实体。您只能删除具有 ID 值的实体。

于 2013-03-28T14:15:55.200 回答
0

PersistenciaMensagemContato您的实体中没有指定 ID 。Hibernate 如何知道要删除哪个引用?

于 2013-03-28T14:08:49.917 回答
-1

This is a good tutorial.... http://www.tutorialspoint.com/hibernate/hibernate_examples.htm

public void deleteEmployee (Integer EmployeeID){
  Session session = factory.openSession();
  Transaction tx = null;
    try {
        tx = session.beginTransaction();
        Employee employee =
                    (Employee) session.get(Employee.class, EmployeeID);
        session.delete(employee);
        tx.commit();
    } catch (HibernateException e) {
        if (tx != null) tx.rollback();
        e.printStackTrace();
    } finally {
        session.close();
    }
}
于 2013-03-28T15:38:48.797 回答