Get all tables in Db using hibernate
1 answer
you can use
List<Object> list = session.createQuery("from java.lang.Object").list();
This will return all persistent objects (thanks to HQL implicit polymorphism) and this is db independent. Note that it excludes tables with no records.
If you need all tables, including empty tables, you can use your own SQL query
List<Object[]> list = session.createSQLQuery("select * from sysibm.systables").list();
The disadvantage to a native query is that it is specific to each database, for example in Oracle the query is "select * from user_tables".
+4
source to share