这居然能通过编译么..Customers c=new Customers();
c.setId(1);
session.delete(c);

解决方案 »

  1.   

    你这里delete的参数应该是一个custom对象 
      

  2.   

    Query q  = session.createQuery("from Customers as c where c.id=:id"); 
    q.setString("id",id);
    q.executeUpdate();....commit();
      

  3.   

    先用这个条件查出这个实体,再删除。如下。
    String hql="from Customers as c where c.id=1"
    Customers cus = (Customers) getHibernateTemplate().find(hql);
    getHibernateTemplate().delete(cus);
    如果你没有用过getHibernateTemplate(),你就用4楼的方法来查,然后再删除查到的实体。
      

  4.   

    你这种写法有问题
    session.delete(entity)  里面应该是个实体对象
    hibernate 的删除机制是先查询再删除
    Session session = HibernateSessionFactory.getSession();
    Transaction tx = session.beginTransaction();
        try {
        Object o = session.get(clazz, key); //clazz是你要删除的对象,key是你的主键值,这个是根据主键查询
        session.delete(o);
        tx.commit();
        } catch (Exception e) {
    if (tx != null)
    tx.rollback(); // 事务回滚
    throw e;
        } 
      

  5.   

    不是吧  session里应该放个对象
    Query q  = session.createQuery("from Customers where c.id=:id");  
    q.setString("id",id); 
    q.executeUpdate(); 
    要提交事务并回滚