问答详情
源自:3-4 Query接口应用编程示例--代码实现

Query query=session.createQuery(hql);报空值异常

package com.imooc.model;


import java.util.List;


import org.hibernate.Query;

import org.hibernate.Session;

import org.junit.Test;

import org.junit.jupiter.api.AfterEach;

import org.junit.jupiter.api.BeforeEach;


import com.imooc.entity.Seller;

import com.imooc.util.HibernateSessionFactory;


public class SellerTest {

private Session session=null;

@BeforeEach

void setUp() throws Exception {

session=HibernateSessionFactory.getSession();

}


@AfterEach

void tearDown() throws Exception {

session.close();

}


@Test

public void testSeller() {

String hql="from Seller";

Query query=session.createQuery(hql);

List<Seller> sellers=query.list();

for(Seller seller:sellers) {

System.out.println(seller);

}

}



}


提问者:风与蓝天 2019-08-18 13:34

个回答

  • 辽工大
    2019-08-19 16:37:49

    你数据库里的表创建 了么?