It seems that, even now in mid-07, and using the Hibernate annotations, I cannot find a good way to generate new "default" column values through into my DDL. I am forced to choose between these unfortunate options:
1. Using the EJB3 standard, but "non-portable", columnDefinition attribute on the Column annotation. This is ugly, and in many cases totally not an option, when having to support multiple databases.
2. Modifying the DDL by hand before using on live databases, thereby not allowing the use of any Hibernate-based automatic tools. This also means that the DDL of the schema is not in synch with what Hibernate would produce if left to its own devices; not a pleasant situation to be sure.
3. Making the column nullable, by using a reference type, like Integer, or Boolean. Now, strictly speaking in Java beans, the standard boolean/Boolean rules are a little crazy, and stupid IMHO. Only bean properties that are the primitive "boolean" are allowed to use the accessor "is<property>" method name format. Properties that are of the reference type Boolean are not allowed to use this bean-convention method name. And this means that, if you happen to try and use these Hibernate beans on JSP pages, or in EL/MVEL/OGNL expressions, et.al., Boolean property accessors have unfortunate names like "getImageType", when "isImageType" is much more appropriate to the semantics.
Either way, we are forced to compromise.
Can there be a way to specify a column's default value that the various dialects can specify to their heart's content? And can this setting be made settable via a new Hibernate extension annotation named something like "DefaultValue", or "Default" maybe?
Since this is a feature request, should I put this into JIRA?
Tom Harris
mailto://tom@tharrisx.homedns.org
http://www.tharrisx.homedns.org/