[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-1814) SchemaUpdate should update existing rows when adding columns that map to a primitive type

Rädle Manuel (JIRA) noreply at atlassian.com
Tue Jun 23 08:14:33 EDT 2009


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

Rädle Manuel commented on HHH-1814:
-----------------------------------

A solution is to provide a new property "defaultValue" in the @Column annotation

e.g.

@Column(defaultValue= "default 11")
 private int primitiveType;


If a default  value is set then these value should set in the Column class
org.hibernate.mapping.Column -> property "defaultValue"

like XML schema update
HbmBinder line 1689 -> column.setDefaultValue( node.attributeValue( "default" ) );

So existing rows where updated if a default value is set.

> SchemaUpdate should update existing rows when adding columns that map to a primitive type
> -----------------------------------------------------------------------------------------
>
>                 Key: HHH-1814
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1814
>             Project: Hibernate Core
>          Issue Type: Improvement
>          Components: core
>    Affects Versions: 3.1.3
>         Environment: Hibernate 3.1.3 with different databases, tested with MySQL 5.0.16/ConnectorJ 3.1.13 as well as SapDB/MaxDB and hSQL
>            Reporter: Christian Aust
>   Original Estimate: 1 hour
>  Remaining Estimate: 1 hour
>
> When SchemaUpdate is started to update a table schema to a given set of mapping metadata, it will create columns in existing tables as needed. If such a column maps to a primitive Java type (i.e. int, long, double, boolean) it is important to update this column's values to some default value other than NULL. Failure to do so will result in Exceptions when Hibernate actually tries to load instance data for such a class from the database, and tries to convert a NULL value back to an int, long, double or boolean using the property setter.
> To avoid this, the result of ALTER statements could include an UPDATE statement as well, updating already existing rows to a reasonable value.
> ALTER TABLE animals ADD COLUMN (age int);
> UPDATE animals SET age = 0 WHERE AGE IS NULL;
> I'd like to see this patch applied to the SchemaUpdate of hibernate, which I happen to use a lot. But since generation of ALTER statements is processed inside org.hibernate.mapping.Table#sqlAlterStrings I can't work around this issue without patching the hibernate core.

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