1

I created the entity patient with a column ID which is the primary key of the table PATIENT. While inserting a new Patient object, I get the following exception:

 WARN: SQL Error: -20001, SQLState: 23502
 org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
 The column "ID" cannot be null.

This is the code creating the Patient object:

    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);

The value id of the Patient object is 1.

I am using struts with Tomcat 6 and Derby 10.9.1.0 and Hibernate 4.

Any help

v.ladynev
  • 16,591
  • 5
  • 37
  • 56
T.Garoui
  • 11
  • 3

1 Answers1

-2

are you using Hibernate ID generation ? ( i guess not since you are feeding the ID). You need to output the Hibernate SQL with input parameters to get an idea what SQL Insert is being generated. How to print a query string with parameter values when using Hibernate

Community
  • 1
  • 1
shark
  • 117
  • 1
  • 5