Test.java:
package cn.xxx.demo;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.junit.Test;
import cn.xxx.domain.Customer;
import cn.xxx.utils.HibernateUtils;
//学习HQL语法
public class Test {
//基本语法
@Test
public void fun1(){
Session session = HibernateUtils.openSession();
Transaction tx = session.beginTransaction();
//----------------------------------------------------
String hql = " select * from cn.xxx.domain.Customer "; //完整写法
String hql2 = " from Customer "; //简单写法 (整个工程中只有一个Customer类,可以省略包名)
String hql3 = " from java.lang.Object "; // 会查询所有配置过orm的数据表。(一般不这样使用)
Query query = session.createQuery(hql3);
List list = query.list();
System.out.println(list);
//----------------------------------------------------
tx.commit();