In Hibernate 3 and 4 you would do something like this
URL configFileURL = getResource(); //some method to get hold of the location of your hibernate.cfg.xml
Configuration configuration = (new Configuration()).configure(configFileURL);
Iterator classMappings = configuration.getClassMappings();
while (classMappings.hasNext()) {
PersistentClass persistentClass = (PersistentClass) classMappings.next();
//do somthing
}
In Hibernate 5 initialise Metadata like this
URL configFileURL = getResource(); //some method to get hold of the location of your hibernate.cfg.xml
StandardServiceRegistry standardRegistry = new StandardServiceRegistryBuilder().configure(configFileURL).build();
Metadata metaData = new MetadataSources(standardRegistry).getMetadataBuilder().build();
And use getEntityBindings() on metadata
Collection<PersistentClass> entityBindings = metadata.getEntityBindings();
Iterator<PersistentClass> iterator = entityBindings.iterator();
while (iterator.hasNext()) {
PersistentClass persistentClass = iterator.next();
//do somthing
}
ClassMetadata
isn't enough? You can get it fromSessionFactory
viaClassMetadata getClassMetadata(String entityName)
. – KinshasaClassMetadata
is not enough. NeedPersistentClass
from metadata. – Chil