开发者

Problems with ArrayList items and hibernate

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 ..

<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);
//                      asser开发者_运维百科tEquals(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->


Have you tried to use

type="long"

instead of

type="java.lang.Long"

as it is in the example in the docs?


Have you turned up hibernate logging to DEBUG to see what it is actually doing?

You can also set the following system properties to "true":

  • hibernate.show_sql
  • hibernate.format_sql

This should dump out the SQL that it is issuing.


My mistake, I inserted some data into database with SQL developer forgot to push the "commit" button :P


Try this

<sql-query name="endDateChecker">
<return-scalar column="PId" type="java.lang.Long"/>
            <![CDATA[select
                        pid as PId
        from
                info          
 </sql-query>

to rule out an issue with the predicate.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜