From: Christian A. (JIRA) <no...@at...> - 2006-06-06 02:43:53
|
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: Hibernate3 Type: Improvement Components: core 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 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 |