the java side solution would probably work in most cases but for maintenance purposes you would want the mapping to be exactly same as what's in the database. here's a scenario:
i create a persistent object let's say with one field
Code:
public String getfield1()
over time i would have a table with data populate for field1.
if i change it now to have a new field, here's the migration issue
Code:
@hibernate.property not-null="true"
public int getIntField()
the update will issue an "alter table" to add the new column intField.
this will cause all the existing records to have the value NULL. the next time you load one of these record it's boom time (unless of course we pre populate the atribute)
i came up with the following solution.
i changed SchemaUpdate and Table classes to generate the DEFAULT keyword. i yet have to integrate with XDoclet so that you could possibly do something like this:
Code:
@hibernate.property not-null="true" default="0"