hibenate 에서 QBC 조회

1002 단어 JAVAHibernate
package dao;

import domain.AccountEntity;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.junit.Test;

import javax.persistence.criteria.CriteriaQuery;

import java.util.List;

import static org.junit.Assert.*;

/**
 * @Author: David.Xiao
 * @Date: 2018/11/7 21:15
 * @Description: QBC                ,                
 */
public class QbcUtilTest {
    /**
     *     
     */
    @Test
    public void queryAllByQbc()
    {
        Session session = HibernateUtil.openSession();
        Transaction tx = session.beginTransaction();
        CriteriaQuery criteriaQuery = session.getCriteriaBuilder().createQuery(AccountEntity.class);
        criteriaQuery.from(AccountEntity.class);

        List list = session.createQuery(criteriaQuery).getResultList();
        for (Object object:list) {
            System.out.println(object.toString());
        }
        tx.commit();
    }
}

좋은 웹페이지 즐겨찾기