Given a class that is mapped in Hibernate, you can get the table name that it is mapped to with the following piece of code.
import org.hibernate.SessionFactory;
import org.hibernate.persister.entity.Joinable;
public String getTableName(SessionFactory sessionFactory, Class<?> mappedClass)
{
ClassMetadata cmd = sessionFactory.getClassMetadata(mappedClass);
//check that the class is mapped to something with a table name
if (cmd == null || !Joinable.class.isInstance(cmd))
return null;
return Joinable.class.cast(cmd).getTableName();
}
Comments