我创建了实体患者,其列ID
是表PATIENT
的主键。插入新的 Patient
对象时,出现以下异常:
WARN: SQL Error: -20001, SQLState: 23502
org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
The column "ID" cannot be null.
这是创建Patient
对象的代码:
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
Session session = sessionFactory.openSession();
Patient patient = new Patient(1L, null, "John", "Kennedy", 12, "USA", "Wall Street");
session.save(patient);
Patient
对象的值 ID 为 1。
我在 Tomcat 6、Derby 10.9.1.0 和 Hibernate 4 中使用 struts。
任何帮助
最佳答案
您是否使用 Hibernate ID 生成? (我想不是因为你正在提供ID)。 您需要输出带有输入参数的 Hibernate SQL,以了解正在生成什么 SQL 插入。 How to print a query string with parameter values when using Hibernate
关于java - hibernate 中 "ID"列不能为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35944020/