As I mentioned before, you can be a bit more generic by looking at Configuration and getting a hold of a PersistenClass instance. By doing this, you can find all properties which map to columns that are not null. Here's some example code I posted in another thread:
Code:
Configuration cfg = HibernateUtil.getConfiguration();
StringBuffer hqlQuery = new StringBuffer();
PersistentClass pc = cfg.getPersistentClass(SomeEntity.class.getName());
Iterator properties = pc.getPropertyIterator();
while(properties.hasNext()) {
Property property = (Property) properties.next();
Iterator columns = property.getColumnIterator();
while(columns.hasNext()) {
Column column = (Column) columns.next();
if(!column.isNullable()) {
/*
* Insert your own code to add this property to your HQL query
*/
}
}
}
Once you've generated your HQL, or SQL for that matter, you can simply execute an update:
Code:
Session session = HibernateUtil.getCurrentSession();
int updatedEntities = s.createQuery(hqlQuery.toString()).executeUpdate();
While not as elegant as some type of mapping attribute, it will do the trick. It's generally a good idea to generate the query strings at startup to avoid any performance hot of creating a query over & over again.