[英]The column “ID” cannot be null with hibernate
我创建的实体患者的列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插入。 使用Hibernate时如何打印带有参数值的查询字符串
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.