vjhiber wrote:
I am trying to get table column names corresponding to persistent object class properties from a hibernate interceptor class.
I have looked at ClassMetaData which provides property Name information but does not provide table schema information. Also looked at org.hibernate.mapping.PersistentClass javadocs, but it is not clear how to get the column names.
Thanks
I am quite late, but in case you haven't found it yet or somebody else is looking for the solution:
Code:
Iterator<Property> props = factoryBean.getConfiguration().getClassMapping(entityClass.getName()).getPropertyClosureIterator();
while (props.hasNext()) {
Iterator<Column> cols = p.getColumnIterator();
while (cols.hasNext()) {
Column c = cols.next();
logger.debug(i + ". column Name: " + c.getName());
logger.trace(i + ". column Nullability: " + c.isNullable());
logger.trace(i + ". column Length: " + c.getLength());
logger.trace(i + ". column Precision: " + c.getPrecision());
}
}
entityClass should be the class you are looking for and replace the FactoryBean with whatever object created your Session. The object should provide you with access to the Configuration.
Don't rely on the column information, though. At least the length is not correct for me using Postgres and Hibernate 3.2.5