当org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
我尝试删除休眠中的记录时,session.delete(cust)
请提供一些帮助。谢谢!
我试图检查 id 列的字段映射。并且在调用 delete 方法之前,id 与cust
对象绑定。
Configuration configuration = new Configuration().configure();
SessionFactory factory = configuration.buildSessionFactory();
Session session = factory.openSession();
long id = 2;
try {
Transaction t = session.beginTransaction();
Customer cust = (Customer) session.get(Customer.class, id);
session.delete(cust);
t.commit();
} catch (HibernateException e) {
System.out.println(e.getLocalizedMessage());
session.getTransaction().rollback();
}
}