[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-3166) @Generated annotation not inserting during insert if column is not-null=true

Paul Benedict (JIRA) noreply at atlassian.com
Wed Sep 30 01:44:57 EDT 2009


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-3166?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=34082#action_34082 ] 

Paul Benedict commented on HHH-3166:
------------------------------------

One feature that I wish Hibernate supported is the ability to insert NULL for generated columns. In particular, MySQL requires that if you want to have generate the current timestamp with multiple timestamp columns:

* http://gusiev.com/2009/04/update-and-create-timestamps-with-mysql/
* http://dev.mysql.com/doc/refman/5.0/en/timestamp.html

By inserting NULL into the Created column, the create timestamp gets auto-generated. If the column is left out of the insert statement (thus accepting the default), you will get the default value. In either case, Hibernate needs to read back the value.

> @Generated annotation not inserting during insert if column is not-null=true
> ----------------------------------------------------------------------------
>
>                 Key: HHH-3166
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3166
>             Project: Hibernate Core
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 3.2.6
>         Environment: MSSQL 9.00.3042.00 
> Hibernate annotations version 3.2.0 GA and also tested 3.30 GA
>            Reporter: Rob
>            Priority: Minor
>
> The @Generated annotation is not working similiar to the hbm generated tag.
> Annotation Mapping:
> @Generated(GenerationTime.INSERT)
> @Column (name="CreatedOn", length=23, nullable=false, insertable=false, updatable=false)
> private Date mCreatedOn; 
> Mapping Document:
> <property name="createdOn" generated="insert" type="TimestampType">
>        	<column name="CreatedOn" length="23"/>
> </property>
> The generated SQL (show_sql=true):
> Hibernate: insert into Zone (CreatedByUserID, ZoneDescription, ZoneFile, ModifiedByUserID, ModifiedOn, ZoneName, RowStatus, SOAExpire, SOAMinimum, SOARefresh, SOARetry, SOAWho, ZoneTTL, ZoneType, ZoneClass) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
> Debug level Hibernate log excerpt:
> 18:37:42 WARN org.hibernate.util.JDBCExceptionReporter 77 SQL Error: 515, SQLState: 23000
> 18:37:42 ERROR org.hibernate.util.JDBCExceptionReporter 78 Cannot insert the value NULL into column 'CreatedOn', table 'DB.dbo.Zone'; column does not allow nulls. INSERT fails. 

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list