我有一個獲取列表項的問題,下面是我的hibernate代碼,在代碼之後有我的方法..和下面是我的junit測試。我怎樣才能確保查詢正確執行,以及如何檢查結果實際上工作..這個查詢應該返回幾個PID ..並把它們放在列表中..現在我90%確定我的列表是總是空..相反,它應該有3周的PID:4573,4593,4693 ..任何人都可以計算出來,我做錯了什麼..爲什麼PID不是我的名單裏面..ArrayList項目和休眠的問題
<sql-query name="endDateChecker">
<return-scalar column="PId" type="java.lang.Long"/>
<![CDATA[select
pid as PId
from
info
where
end_date < trunc(sysdate)]]>
</sql-query>
< - HIBERNATE->
public List<Long> findItemByPIdEndDate() throws ROSException {
List<Long> list = null;
try{
Session session = sessionFactory.getCurrentSession();
Query query = session.getNamedQuery("endDateChecker");
list = query.list();
for (Long long1 : list) {
logger.info(long1);
}
}catch (HibernateException e){
throw new DataAccessException(e.getMessage());
}
return list;
}
< -METHOD->
public class FindItemByPIdEndDateTest{
private static final Log logger = ROSLogFactory.getLog(FindItemByPIdEndDateTest.class);
private ApplicationContext beanFactory;
private PersistenceMngt lps = null;
@Before
public void setUp() throws Exception {
beanFactory = new ClassPathXmlApplicationContext("/resources/ros-conf/engine-conf/applicationContext.xml");
lps = (PersistenceMngt)beanFactory.getBean("persistenceMngtService");
}
@After
public void tearDown() throws Exception {
}
@Test
public void testFindItemByPIdEndDate(){
List<Long> itemdb = null;
try {
itemdb = lps.findLroByPIdEndDate();
// assertNull("List is empty", itemdb);
// assertEquals(4573, itemdb.indexOf(0));
// assertEquals(3, itemdb.size());
// assertEquals(4593, itemdb.indexOf(1));
// assertEquals(4693, itemdb.indexOf(2));
} catch (ROSException e) {
e.printStackTrace();
fail(e.getMessage());
}
}
}
< -TEST->
同樣的事情..我得到相同的結果..意義項目列表仍然是空的 –