You will want to use the ClassMetaData which can be accessed from your session factory.
Code:
EntityPersister ep = (EntityPersister)sessionFactory.getClassMetadata(Foo.class);
ClassMetadata cm = ep.getClassMetadata();
String[] properties = cm.getPropertyNames();
List<String> columnNames = new ArrayList();
We get the property names from the class meta data of Foo.class.
Then you will need to figure out what type of mapping it is [SingleTableEntityPersister, JoinedSubclassEntityPersister, UnionSubclassEntityPersister]. For simplicity, I will give the example as follows:
Code:
String columnName;
String tableName;
if(ep.getClass().equals(SingleTableEntityPersister.class))
{
tableName = ((SingleTableEntityPersister)ep).getTableName();
for(int i=0, j=properties.length, i<j; i++)
{
if(((SingleTableEntityPersister)ep).getPropertyColumnNames(properties[i]).length>0)
{
columnNames.Add(((SingleTableEntityPersister)ep).getPropertyColumnNames(properties[i]));
}
}
}