Having Hibernate and MSSQL env. I have faced with error: 'Cannot insert the value NULL into column 'comment_id', table 'CHT.dbo.reporter_comments'; column does not allow nulls. INSERT fails.' Hibernate configuration:
<id unsaved-value = "null" type = "int" name="commentId" column="comment_id">
<generator class="identity"/>
</id>
<property name="reporterId" column="REPORTERID" />
<property name="adminComments" column="COMMENT" />
<property name="commentDate" column="COMMENT_DATE"/>
<property name="commentBy" column="COMMENT_BY"/>
'comment_id' column has 'identity' property in db: if i do insertion using db client:
insert into REPORTER_COMMENTS (REPORTERID, COMMENT, COMMENT_DATE, COMMENT_BY)
values (15119, 'test', '2013-03-04 05:45:25', 'admin');
it works perfect for me.
Hibernate logs:
DEBUG hibernate.SQL - insert into REPORTER_COMMENTS (REPORTERID, COMMENT, COMMENT_DATE, COMMENT_BY) values (?, ?, ?, ?) DEBUG hibernate.jdbc.AbstractBatcher - preparing statement DEBUG hibernate.persister.entity.AbstractEntityPersister - Dehydrating entity: [---.ReporterComments#] DEBUG hibernate.type.LongType - binding '15119' to parameter: 1 DEBUG hibernate.type.StringType - binding 'test' to parameter: 2 DEBUG hibernate.type.TimestampType - binding '2013-03-04 06:13:02' to parameter: 3 DEBUG hibernate.type.StringType - binding 'dw' to parameter: 4 DEBUG hibernate.jdbc.AbstractBatcher - about to close PreparedStatement (open PreparedStatements: 1, globally: 1) DEBUG hibernate.jdbc.AbstractBatcher - closing statement DEBUG hibernate.util.JDBCExceptionReporter - could not insert: [---.ReporterComments] [insert into REPORTER_COMMENTS (REPORTERID, COMMENT, COMMENT_DATE, COMMENT_BY) values (?, ?, ?, ?)] java.sql.SQLException: [BEA][SQLServer JDBC Driver][SQLServer]Cannot insert the value NULL into column 'comment_id', table 'CHT.dbo.reporter_comments'; column does not allow nulls. INSERT fails.
Thanks!