I\'m trying to iterate over all of my tables so I can truncate each one (at the beginning of each of my JBehave tests).
I thought I would be able to:
If you still have access to the Hibernate Configuration object, you can do this:
for (Iterator iter=configuration.getClassMappings(); iter.hasNext();) {
PersistentClass persistentClass = (PersistentClass)iter.next();
String table = persistentClass.getTable().getName();
// Code to truncate table (or just use a query with session.executeUpdate)
}
That assumes you have one table per entity and you only care about the tables that are mapped. Otherwise, you probably need to do something with the underlying connection and the DatabaseMetaData, e.g.:
session.connection().getMetaData().getTables(catalog, schemaPattern, tableNamePattern, types)