3

I am writing below query to get record for today date

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<GroupTweetOrder> usersOrder= query.list();

and in Java class for his table

@NamedQueries({
    @NamedQuery(name = "findUsersOrder", query = "FROM GroupTweetOrder WHERE gtoAddedDate >= :todayAtMidnight and gtoAddedDate < :tomorrowAtMidnight")
})

But when ever i am trying to run this HSQL i am getting

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(<generated>)
    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(<generated>)
    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
2
  • Problem comes from GroupDistDAO line 82 com.ccc.spring.dao.GroupDistDAO.fetchTodayGroupOrder(GroupDistDAO.java:82). Seems like problem with your input String i guess ? Commented Jun 24, 2014 at 7:52
  • This is List<GroupTweetOrder> usersOrder= query.list(); Commented Jun 24, 2014 at 8:22

3 Answers 3

9

This error in Hibernate apparently occurs when an empty varchar column in a table is loaded into a char or Character field. I received the same error when I had a field defined in Java as char, in the SQL as "varchar(10)", and the data in the table was an empty string (''). As long as the table data was a single character, it worked fine. (Running Hibernate 3.6.10)

See https://forum.hibernate.org/viewtopic.php?f=1&t=1008581 for a description of the failing code.

Sign up to request clarification or add additional context in comments.

Comments

1

This issue is not coming due to date ....This issue due to character field in table for which i am using char as a data type so i made changes char datatype to TinyInt(1) Now this work fine

Comments

-3

according to Java SE 7 Doc

Thrown by String methods to indicate that an index is either negative or greater than
the size of the string. For some methods such as the charAt method, this exception 
also is thrown when the index is equal to the size of the string.

see more here.

5 Comments

Agre but here i am not doing anything which you mentioned here
i have just mentioned cause of exception you need to debug your code.
If i am able to find the issue with debug i never asked question here
ok so what my point is that its not Hibernate SQL Exception its Java String exception. print the query 1st and see what session.getNamedQuery("findUsersOrder") will return and inspect the query you will may found your error.
This issue i am getting when i have data in current date otherwise its not giving exception

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.