import org.hibernate.cfg.Configuration;
import org.hibernate.mapping.PersistentClass;
public class HibernateConfigurationHelper {
private static Configuration hibernateConf = new Configuration();
private static PersistentClass getPersistentClass(Class clazz) {
synchronized (HibernateConfigurationHelper.class) {
PersistentClass pc = hibernateConf.getClassMapping(clazz.getName());
if (pc == null) {
hibernateConf = hibernateConf.addClass(clazz);
pc = hibernateConf.getClassMapping(clazz.getName());
}
return pc;
}
}
public static String getTableName(Class clazz) {
return getPersistentClass(clazz).getTable().getName();
}
public static String getPkColumnName(Class clazz) {
return getPersistentClass(clazz).getTable().getPrimaryKey()
.getColumn(0).getName();
}
}