Connecting Tech Pros Worldwide Help | Site Map

Retrieve list items

Newbie
 
Join Date: Oct 2009
Posts: 1
#1: 4 Weeks Ago
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 ..

Expand|Select|Wrap|Line Numbers
  1. <sql-query name="endDateChecker">
  2. <return-scalar column="PId" type="java.lang.Long"/>
  3. <![CDATA[select
  4.               pid as PId 
  5.               from  
  6.               info       
  7.               where   
  8.              end_date < trunc(sysdate)]]>     
  9. </sql-query>
<-HIBERNATE->

Expand|Select|Wrap|Line Numbers
  1. public List<Long> findItemByPIdEndDate() throws ROSException {                
  2.  
  3. List<Long> list = null;     
  4.            try{                   
  5.      Session session = sessionFactory.getCurrentSession();                           
  6.  
  7. Query query = session.getNamedQuery("endDateChecker");                        
  8.  
  9. list = query.list();                      
  10.   for (Long long1 : list) {                           
  11.      logger.info(long1);                    
  12.     }               
  13.  }catch (HibernateException e){    
  14.                     throw new DataAccessException(e.getMessage());                
  15.  
  16. }               
  17.  return list;       
  18.  }
<-METHOD->

Expand|Select|Wrap|Line Numbers
  1. public class FindItemByPIdEndDateTest{        
  2. private static final Log logger = ROSLogFactory.getLog(FindItemByPIdEndDateTest.class);       
  3. private ApplicationContext beanFactory;        
  4. private  PersistenceMngt lps = null;        
  5. @Before        
  6. public void setUp() throws Exception {               
  7.  beanFactory = new ClassPathXmlApplicationContext("/resources/ros-conf/engine-conf/applicationContext.xml");                
  8. lps = (PersistenceMngt)beanFactory.getBean("persistenceMngtService");        
  9.  
  10. }       
  11. @After       
  12.  public void tearDown() throws Exception {        
  13. }        
  14. @Test       
  15.  public void testFindItemByPIdEndDate(){         
  16.        List<Long> itemdb = null;              
  17.   try {                       
  18.  itemdb = lps.findLroByPIdEndDate(); //          
  19.   assertNull("List is empty", itemdb);//                     
  20.   assertEquals(4573, itemdb.indexOf(0));//                    
  21.   assertEquals(3, itemdb.size());//    
  22.   assertEquals(4593, itemdb.indexOf(1));//       
  23.   assertEquals(4693, itemdb.indexOf(2));                
  24. } catch (ROSException e) {             
  25.            e.printStackTrace();   
  26.            fail(e.getMessage());            
  27.     }                   
  28. }}
<-TEST->
Reply

Tags
hibernate, java, list