Hibernate-Criteria查询(4)Annotation

package junit.test;

import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.List;

import hibch06.dao.HibernateSessionFactory;
import hibch06.pojo.Dept;


import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.criterion.Restrictions;
import org.junit.Test;

public class Hibch06Test_anno {

    @Test
    public void test() {
        //获取sessionFactory 使用注解配置来构建
        SessionFactory sf=new AnnotationConfiguration().configure().buildSessionFactory();
        Session session=sf.openSession();
        Dept dept=(Dept)session.get(Dept.class, 10);
        System.out.println(dept.getDname());
    }


}

你可能感兴趣的:(Hibernate)