Hibernate loading all entities utilizing 1st or 2nd level cache
问题 We have an entire table of entities that we need to load during a hibernate session and the only way I know to load all entities is through an HQL query: public <T> List<T> getAllEntities(final Class<T> entityClass) { if (null == entityClass) throw new IllegalArgumentException("entityClass can't be null"); List<T> list = castResultList(createQuery( "select e from " + entityClass.getSimpleName() + " e ").list()); return list; } We use EHcache for 2nd level caching. The problem is this gets