title: Hibernate SQL Exception java.lang.StringIndexOutOfBoundsException: String index out of range
body: <p>I am writing below query to get record for today date</p>
  
  <pre><code>Session session = getSessionFactory().getCurrentSession();
  DateTime todayAtMidnight = new DateTime().withTimeAtStartOfDay();
  DateTime tomorrowAtMidnight = todayAtMidnight.plusDays(1);
  Query query = session.getNamedQuery("findUsersOrder")
      .setTimestamp("todayAtMidnight", todayAtMidnight.toDate())
      .setTimestamp("tomorrowAtMidnight", tomorrowAtMidnight.toDate());
  List&lt;GroupTweetOrder&gt; usersOrder= query.list();
  </code></pre>
  
  <p>and in Java class for his table </p>
  
  <pre><code>@NamedQueries({
      @NamedQuery(name = "findUsersOrder", query = "FROM GroupTweetOrder WHERE gtoAddedDate &gt;= :todayAtMidnight and gtoAddedDate &lt; :tomorrowAtMidnight")
  })
  </code></pre>
  
  <p>But when ever i am trying to run this HSQL i am getting</p>
  
  <pre><code>Jun 23, 2014 5:13:11 PM com.sun.faces.context.AjaxExceptionHandlerImpl log
  SEVERE: JSF1073: javax.faces.event.AbortProcessingException caught during processing of INVOKE_APPLICATION 5 : UIComponent-ClientId=formcontract:iconOnly, Message=java.lang.StringIndexOutOfBoundsException: String index out of range: 0
  Jun 23, 2014 5:13:11 PM com.sun.faces.context.AjaxExceptionHandlerImpl log
  SEVERE: java.lang.StringIndexOutOfBoundsException: String index out of range: 0
  javax.faces.event.AbortProcessingException: java.lang.StringIndexOutOfBoundsException: String index out of range: 0
      at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:182)
      at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)
      at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:769)
      at javax.faces.component.UICommand.broadcast(UICommand.java:300)
      at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
      at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
      at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
      at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
      at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
      at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:98)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:145)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
      at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
      at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1001)
      at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
      at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      at java.lang.Thread.run(Thread.java:722)
  
  Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: 0
      at java.lang.String.charAt(String.java:658)
      at org.hibernate.type.descriptor.java.CharacterTypeDescriptor.wrap(CharacterTypeDescriptor.java:79)
      at org.hibernate.type.descriptor.java.CharacterTypeDescriptor.wrap(CharacterTypeDescriptor.java:33)
      at org.hibernate.type.descriptor.sql.VarcharTypeDescriptor$2.doExtract(VarcharTypeDescriptor.java:66)
      at org.hibernate.type.descriptor.sql.BasicExtractor.extract(BasicExtractor.java:65)
      at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:269)
      at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:265)
      at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:238)
      at org.hibernate.type.AbstractStandardBasicType.hydrate(AbstractStandardBasicType.java:357)
      at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2701)
      at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1541)
      at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1473)
      at org.hibernate.loader.Loader.getRow(Loader.java:1373)
      at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:640)
      at org.hibernate.loader.Loader.doQuery(Loader.java:850)
      at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:289)
      at org.hibernate.loader.Loader.doList(Loader.java:2447)
      at org.hibernate.loader.Loader.doList(Loader.java:2433)
      at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2263)
      at org.hibernate.loader.Loader.list(Loader.java:2258)
      at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:470)
      at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:355)
      at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:196)
      at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1161)
      at org.hibernate.internal.QueryImpl.list(QueryImpl.java:101)
      at com.ccc.spring.dao.GroupDistDAO.fetchTodayGroupOrder(GroupDistDAO.java:82)
      at com.ccc.spring.service.GroupDistService.fetchTodayGroupOrder(GroupDistService.java:40)
      at com.ccc.spring.service.GroupDistService$$FastClassBySpringCGLIB$$a552f952.invoke(&lt;generated&gt;)
      at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
      at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:711)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
      at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:98)
      at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:262)
      at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
      at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:644)
      at com.ccc.spring.service.GroupDistService$$EnhancerBySpringCGLIB$$647c04d.fetchTodayGroupOrder(&lt;generated&gt;)
      at com.ccc.managedController.TweetDistributionManagedBean.sendGroupTweets(TweetDistributionManagedBean.java:175)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:601)
      at org.apache.el.parser.AstValue.invoke(AstValue.java:264)
      at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278)
      at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:153)
      ... 31 more
  </code></pre>