Hi,
There have been a modification in hibernate behaviour when adding column. In JbossAS5 (hibernate3), when using the JPA @Column(nullable=false) with hibernate.hbm2ddl.auto=update, hibernate was : - Creating a not null column if table does not exist - Creating a nullable column if table already exists This was quite useful for me, as I could use the same code on new databases and when migrating existing databases (I was juste altering in SQL the column created by hibernate to add the not null constraint after updating the column with default values)
Since JBossAS7 and wildfly8 (hibernate4), the behaviour has been changed. When using the not null annotation, hibernate always tries to add a not null column and fails because there is already data in the table...
I cannot set a default value by annotation, because my code must work on different databases with different column type (and there is no standard annotation for that)... My only solution seems to disable the hibernate.hbm2ddl.auto=update and alter the tables manually. The hibernate automatic alter table was a really cool feature... Is there any way to configure hibernate to switch back to the previous behaviour (always adding nullable columns when altering a table) ?
Thanks for your help
|