FileDocCategorySizeDatePackage
QueryTest3.javaAPI DocExample1515Tue Jan 25 00:10:58 GMT 2005com.oreilly.hh

QueryTest3

public class QueryTest3 extends Object
Retrieve data as objects

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)
Look up and print all entities when invoked from the command line.

        // Create a configuration based on the properties file we've put
        // in the standard place.
        Configuration config = new Configuration();

        // Tell it about the classes we want mapped, taking advantage of
        // the way we've named their mapping documents.
        config.addClass(Track.class).addClass(Artist.class);
        config.addClass(Album.class);

        // Get the session factory we can use for persistence
        SessionFactory sessionFactory = config.buildSessionFactory();

        // Ask for a session using the JDBC information we've configured
        Session session = sessionFactory.openSession();
        try {
            // Print every object in the database.
            List all = session.find("from java.lang.Object");

            for (ListIterator iter = all.listIterator() ;
                 iter.hasNext() ; ) {
                System.out.println(iter.next());
            }
        } finally {
            // No matter what, close the session
            session.close();
        }

        // Clean up after ourselves
        sessionFactory.close();