Spring-MVC, Hibernate : Timebased query returns no entries

I am working on a Spring-MVC application in which I am checking in the database for entries which are specific days old. Before checking for it, I created some entries thorugh the programs interface, and then ran the request, but it returns empty List. The same code I am using for similar type of Object, data, and it works. I don’t know what I am doing wrong. Kindly let me know..

GroupNotesDAOImpl :

   @Override
    public List<GroupNotes> searchNotesByDays(int days, int mcanvasid) {
        Session session = this.sessionFactory.getCurrentSession();
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DAY_OF_YEAR, -days);
        long daysAgo = cal.getTimeInMillis();
        Timestamp nowMinusDaysAsTimestamp = new Timestamp(daysAgo);
        GroupCanvas groupCanvas = (GroupCanvas) session.get(GroupCanvas.class,mcanvasid);
        Query query = session.createQuery("from GroupSection as n where n.currentcanvas.mcanvasid=:mcanvasid");
        query.setParameter("mcanvasid", mcanvasid);
        List<GroupSection> sectionList = query.list();
        List<GroupNotes> notesList = new ArrayList<GroupNotes>();
        for (GroupSection e : sectionList) {
            GroupSection groupSection = (GroupSection) session.get(GroupSection.class,e.getMsectionid());
            Query query1 = session.createQuery("from GroupNotes as n where n.ownednotes.msectionid=:msectionid and n.noteCreationTime >:limit");
            query1.setParameter("limit", nowMinusDaysAsTimestamp);
            query1.setParameter("msectionid",e.getMsectionid());
            notesList.addAll(query1.list());
        }
//It never enters in below for loop.
        for(GroupNotes groupNotes : notesList){
            System.out.println("Group notes found are "+groupNotes.getMnotetext());
        }
        return notesList;
    }

NotesDAOImpl :

  @Override
    public List<Notes> searchNotesByDays(int days, int canvasid) {
        Session session = this.sessionFactory.getCurrentSession();
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DAY_OF_YEAR, -days);
        long daysAgo = cal.getTimeInMillis();
        Timestamp nowMinusDaysAsTimestamp = new Timestamp(daysAgo);
        Query query = session.createQuery("from Section as n where n.canvas2.canvasid=:canvasid");
        query.setParameter("canvasid", canvasid);
        List<Section> sectionList = query.list();
        List<Notes> notesList = new ArrayList<Notes>();
        for (Section e : sectionList) {
            Query query1 = session.createQuery("from Notes as n where n.section1.sectionid=:sectionid and n.noteCreationTime >:limit");
            query1.setParameter("limit", nowMinusDaysAsTimestamp);
            query1.setParameter("sectionid",e.getSectionid());
            notesList.addAll(query1.list());
        }
        return notesList;
    }

The same way I am calling in NotesDAOImpl and it works. I have the entries in db, that I am sure about. Any help would be nice. Thanks a lot.


Source: sql

Leave a Reply