I believe you are looking for the same thing I was looking for... and found!
I use custom Hibernate templates to generate my Java code. I just took a copy of theirs and started messing around. It sounds scarier than it is - trust me.
I added the following code to the PojoFields.ftl file:
// These static property values are being generated by the POJO templates (PojoFields.ftl)
<#foreach field in pojo.getAllPropertiesIterator()>
<#if pojo.getMetaAttribAsBool(field, "gen-property", true)>
<#assign name = pojo.getPropertyName(field) type = pojo.getJavaTypeName(field, jdk5)>
public static final String ${field.name}_propname = "${field.name}";
<#foreach column in field.getColumnIterator()>
<#if pojo.getJavaTypeName(field, jdk5) == "String">
public static final int ${field.name}_len = ${column.getLength()?c};
<#break>
</#if>
</#foreach>
</#if>
</#foreach>
For all properties, it generates a public final static String that has the property name.
For String properties, it generates a public final static int that has the field length.
public static final String postalCode_propname = "postalCode";
public static final int postalCode_len = 15;
As long as I always use these static variables and never hard-code their values, I will avoid having RunTime errors related to a database structure change.
Examples:
Criteria criteria = session.createCriteria(ClPost.class).add(
Restrictions.ne(ClPost.postalCode_propname, "90210"));
String hql = "select e." + ClPost.postalCode_propname
+ " from " + ClPost.class.getSimpleName() + " as e";