I have a problem with getting the list items, below is my hibernate code, after that code there is my method ..and below that is my junit test. How can I make sure that query is executing properly, and how can I check that results actually work .. this query should return couple of pids .. and put them in the list.. now I'm 90 % sure that my list is always empty .. instead it should have 3 pids : 4573, 4593, 4693 .. can anyone figure it out what I'm doing wrong .. why the pids are not inside my list ..
<-HIBERNATE->
<-METHOD->
<-TEST->
Code:
<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>
Code:
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; }
Code:
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()); } }}