I am trying to convert from String to Calendar,but always it is giving the exception.
我正在尝试从字符串转换到日历,但它总是给出异常。
Here is my code:-
这是我的代码:-
public List<ClassA> getData(String fromDateTime, String toDateTime, Integer apiId)
throws DAOException, ParseException {
Calendar cal1 = Calendar.getInstance();
Calendar cal2 = Calendar.getInstance();
DateFormat df=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
cal1.setTime(df.parse(fromDateTime));
cal2.setTime(df.parse(toDateTime));
return findByCriteria(Restrictions.eq("apiId", apiId),
Restrictions.between("searchGenerationTime", fromDateTime, toDateTime));
}
please someone can told me where i am wrong in this code ?? lets assume fromDateTime & toDateTime are user input as 2014-04-02 19:24:43 & 2014-04-03 12:03:51 respectively. Thanks.
谁能告诉我这个密码哪里错了?假设fromDateTime和toDateTime分别为用户输入2014-04-02 19:24:43和2014-04-03 12:03:51。谢谢。
Edited:- Here is my stack trace
编辑:-这是我的堆栈跟踪。
java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Calendar
at org.hibernate.type.descriptor.java.CalendarTypeDescriptor.unwrap(CalendarTypeDescriptor.java:40)
at org.hibernate.type.descriptor.sql.TimestampTypeDescriptor$1.doBind(TimestampTypeDescriptor.java:53)
at org.hibernate.type.descriptor.sql.BasicBinder.bind(BasicBinder.java:91)
at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:283)
at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:278)
at org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:1873)
at org.hibernate.loader.Loader.bindParameterValues(Loader.java:1844)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1716)
at org.hibernate.loader.Loader.doQuery(Loader.java:801)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274)
at org.hibernate.loader.Loader.doList(Loader.java:2542)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276)
at org.hibernate.loader.Loader.list(Loader.java:2271)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:119)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1716)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:347)
at com.via.database.util.DAOUtil.findByCriteriaInternal(DAOUtil.java:227)
at com.via.database.util.DAOUtil.findByCriteria(DAOUtil.java:198)
at com.via.database.dao.hibernate.GenericHibernateDAO.findByCriteria(GenericHibernateDAO.java:175)
at com.eos.accounts.database.dao.hibernate.HotelSearcherRequestResponseDao.getData(HotelSearcherRequestResponseDao.java:53)
at com.eos.hotels.HotelSearcherUtility.getHotelSearchRequestResopnseData(HotelSearcherUtility.java:50)
at com.eos.b2c.ui.B2cCallcenterNavigation.doGetExtension(B2cCallcenterNavigation.java:9568)
at com.eos.b2c.ui.B2cCallcenterNavigation.doGet(B2cCallcenterNavigation.java:5851)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.eos.accounts.UserManagerFilter.doFilter(UserManagerFilter.java:972)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:470)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:701)
2 个解决方案
#1
0
I think the return statement should be as follows:
我认为退货声明应该如下:
return findByCriteria(Restrictions.eq("apiId", apiId),
Restrictions.between("searchGenerationTime", cal1, cal2));
#2
0
After analyzing exception stack trace, I found that entity ClassA has a Calendar field searchGenerationTime mapped to SQL timestamp column.
在分析异常堆栈跟踪之后,我发现entity ClassA有一个映射到SQL时间戳列的日历字段searchGenerationTime。
For this case, you are allowed to pass only arguments of these classes:
对于这种情况,您只能传递这些类的参数:
- java.util.Calendar
- java.util.Calendar
- java.sql.Date
- java.sql.Date
- java.sql.Time
- java.sql.Time
- java.sql.Timestamp
- java.sql.Timestamp
- java.util.Date
- java.util.Date
You can see this in hibernate source code.
您可以在hibernate源代码中看到这一点。
In fact, where from Hibernate knows about your date format ("yyyy-MM-dd HH:mm:ss") ?
实际上,在Hibernate中,哪里知道您的日期格式(“yyyyyy - mm -dd:mm:ss”)?
#1
0
I think the return statement should be as follows:
我认为退货声明应该如下:
return findByCriteria(Restrictions.eq("apiId", apiId),
Restrictions.between("searchGenerationTime", cal1, cal2));
#2
0
After analyzing exception stack trace, I found that entity ClassA has a Calendar field searchGenerationTime mapped to SQL timestamp column.
在分析异常堆栈跟踪之后,我发现entity ClassA有一个映射到SQL时间戳列的日历字段searchGenerationTime。
For this case, you are allowed to pass only arguments of these classes:
对于这种情况,您只能传递这些类的参数:
- java.util.Calendar
- java.util.Calendar
- java.sql.Date
- java.sql.Date
- java.sql.Time
- java.sql.Time
- java.sql.Timestamp
- java.sql.Timestamp
- java.util.Date
- java.util.Date
You can see this in hibernate source code.
您可以在hibernate源代码中看到这一点。
In fact, where from Hibernate knows about your date format ("yyyy-MM-dd HH:mm:ss") ?
实际上,在Hibernate中,哪里知道您的日期格式(“yyyyyy - mm -dd:mm:ss”)?