<set name="orderses" inverse="false" cascade="all" >
<key>
<column name="CUSTOMER_ID" not-null="true" />
</key>
<one-to-many class="test.Hibernate.Orders" />
</set>
<key>
<column name="CUSTOMER_ID" not-null="true" />
</key>
<one-to-many class="test.Hibernate.Orders" />
</set>
还是报错!!
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");
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
Customer c = new Customer(new Long(6),"liuwei","liuwei");
session.delete(c);
你new一个对象,但并没有保存进数据库,你再删除c?请问,你删除什么?
.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"); 这样写的话还是错的.报一样的异常啊.而且数据库都不为空的