HIBERNATE JBoss.org
 |  Register  | 
     
News 
About 
   Feature List 
   Road Map 
Documentation 
   Related Projects 
   External Documentation 
Download 
Forum & Mailinglists 
Support & Training 
JIRA Issue Tracking
Wiki Community Area


Hibernate Public Training Courses


Get Hibernate in Action eBook!


JavaWorld 2003 Finalist


Jolt Award 2004 Winner
      
Documentation > Community Area > Simple test case

Simple test case

A simple junit that iterates the whole Hibernate configuration checking is the SQL tables and columns are right. If your database data is huge, change session.find() with session.iterate()

public class HibernateTest extends TestCase {

    public void testEverything() throws Exception {
        SessionFactory sessionFactory = getSessionFactory();
        Map metadata = sessionFactory.getAllClassMetadata();
        for (Iterator i = metadata.values().iterator(); i.hasNext(); ) {
            Session session = sessionFactory.openSession();
            try {
                EntityPersister persister = (EntityPersister) i.next();
                String className = persister.getClassName();
                log.debug("select: " + className);
                List result = session.find("from " + className + " c");
                log.debug("returned " + result.size() + " records for " + className);
            } finally {
                session.close();
            }
        }
    }

}
      

coWiki