0

I wrote a small query. It is executed successful, but sometimes it throws the following exception:

org.hibernate.exception.GenericJDBCException: could not execute query

My Java code:

public List<Building> getSights(String sightId)
{ 
    List<Building> bdList = new ArrayList<Building>();
    Building bld=null;
    Session session = null;
    try{
        session = getHibernateTemplate().getSessionFactory().openSession();
        Query qu = session.createSQLQuery("select distinct bd.TITLE, bd.ID from building_details bd");

        List li = qu.list();
        for (Iterator itr = li.iterator(); itr.hasNext();) {
            Object[] obj = (Object[]) itr.next();
            String sightName = (String) obj[0];
            String sightId = (String) obj[1];

            bld = new Building();

            bld.setSightNames(sightName);
            bld.setSightId(sightId);

            bdList.add(bld);
        }
    }
    catch(Exception e){
       e.printStackTrace();
    } finally {
        if(session != null){
            session.close();
        }
    }

    return bdList;
}

I think my code should work perfectly fine, but it shows the error on the List li = qu.list(); line.

Does anyone know what's wrong with my code?

full exception here

2016-04-21 12:48:26,608  WARN http-8090-5   org.hibernate.util.JDBCExceptionReporter - SQL Error: 0, SQLState: null
2016-04-21 12:48:26,608 ERROR http-8090-5    org.hibernate.util.JDBCExceptionReporter - Cannot get a connection, pool error Timeout waiting for idle object
org.hibernate.exception.GenericJDBCException: could not execute query
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:2220)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2108)
at org.hibernate.loader.Loader.list(Loader.java:2103)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:289)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1696)
at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:152)
Sri
  • 179
  • 3
  • 9
  • 19

0 Answers0