package com.oreilly.hh;
import net.sf.hibernate.*;
import net.sf.hibernate.cfg.Configuration;
import net.sf.hibernate.expression.*;
import java.sql.Time;
import java.util.*;
/**
* Retrieve data as objects
*/
public class QueryTest3 {
/**
* Look up and print all entities when invoked from the command line.
*/
public static void main(String args[]) throws Exception {
// 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();
}
}
|