querytest3.java
来自「Hiberante程序高手秘籍的源代码」· Java 代码 · 共 50 行
JAVA
50 行
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(); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?