final Session session = getSession(); try { System.out.println("querying all the managed entities..."); final Metamodel metamodel = session.getSessionFactory().getMetamodel(); for (EntityType<?> entityType : metamodel.getEntities()) { final String entityName = entityType.getName(); final Query query = session.createQuery("from " + entityName); System.out.println("executing: " + query.getQueryString()); for (Object o : query.list()) { System.out.println(" " + o); } } } finally { session.close(); }
原文:https://www.cnblogs.com/cheneyx/p/8902452.html