<set name="orderses" inverse="false" cascade="all" >
            <key>
                <column name="CUSTOMER_ID" not-null="true" />
            </key>
            <one-to-many class="test.Hibernate.Orders" />
        </set>

解决方案 »

  1.   

    这位大哥,cascade是all也不对.当然,这里必须是要改的.
    还是报错!!
      

  2.   

    关键报错如下:
      SessionFactory sf = new Configuration().configure()
           .buildSessionFactory();
      Session session = sf.openSession();
      Transaction tx = session.beginTransaction();
      Customer c  = new Customer(new Long(6),"liuwei","liuwei");
      session.delete(c);
      tx.commit();
      session.close();
      System.out.println(c+"_______________1");
      

  3.   

    上边的粘错了
    Caused by: java.sql.BatchUpdateException: Data truncation: Column was set to data type implicit default; NULL supplied for NOT NULL column 'CUSTOMER_ID' at row 1
      

  4.   

    倒,你自己看
    Customer c  = new Customer(new Long(6),"liuwei","liuwei");
      session.delete(c);
    你new一个对象,但并没有保存进数据库,你再删除c?请问,你删除什么?
      

  5.   

    SessionFactory sf = new Configuration().configure()
           .buildSessionFactory();
      Session session = sf.openSession();
      Transaction tx = session.beginTransaction();
      Customer c  = (Customer)session.load(Customer.class,new Long(1));
      System.out.println("要删除对象的主键是: " + c.getId());
      session.delete(c);
      tx.commit();
      session.close();
      System.out.println(c+"_______________1"); 这样写的话还是错的.报一样的异常啊.而且数据库都不为空的