HibernateTemplate问题!

为什么我用HibernateTemplate方法返得不到查询结果?
public class RoomDaoImpl extends HibernateDaoSupport implements RoomDao{
public List findUnbookroom()throws Exception{
//String hql="from ROOMS where booked=?";
String hql="from ROOMS";

//return (List)getHibernateTemplate().find(hql,new Integer(0));
return (List)getHibernateTemplate().find(hql);
}

}


public class RoomserviceImpl implements Roomservice{
private RoomDao roomDao=new RoomDaoImpl();
public List findUnbookroom()throws Exception{
return roomDao.findUnbookroom();
}
}

下面是我的测试代码:
public class test2 extends TestCase {

public void test() throws Exception{
Roomservice roomservice=new RoomserviceImpl();
List unbookroomlist=roomservice.findUnbookroom();
Room room=(Room)unbookroomlist.get(0);
//Room room=roomservice.getSelectId(1);
//assertEquals(null,room);
int size=unbookroomlist.size();
//assertEquals("zhong",room.getType());
assertEquals(1,size);
}

}


测试出现红条:
java.lang.NullPointerException
at com.lingirl.RoomDaoImpl.findUnbookroom(RoomDaoImpl.java:21)
at com.lingirl.RoomserviceImpl.findUnbookroom(RoomserviceImpl.java:10)
at com.lingirl.test2.test(test2.java:15)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

不知道为什么返回不了查询结果,请问我写的代码有错误吗?
最好谁可以指教一下有关HIBERNATETEMPLATE的用法,谢谢了~~

你可能感兴趣的:(java,eclipse,spring,Hibernate,JUnit)