【发布时间】:2016-02-23 00:13:32
【问题描述】:
在持续时间内 - 一切正常,但是当我尝试执行下一个查询时,我会遇到异常
Query query = sessionFactory.getCurrentSession()
.createSQLQuery("Select * From QUOTE").addScalar("id", StandardBasicTypes.LONG)
.addScalar("date", StandardBasicTypes.TIMESTAMP) <-- this throw exception
.addScalar("interval", myEnumType)
.addScalar("open", StandardBasicTypes.DOUBLE)
.addScalar("high", StandardBasicTypes.DOUBLE)
.addScalar("low", StandardBasicTypes.DOUBLE)
.addScalar("close", StandardBasicTypes.DOUBLE)
.addScalar("volume", StandardBasicTypes.INTEGER).setResultTransformer(Transformers.aliasToBean(QuoteEntity.class));
return query.list();
执行后出现错误:
2015-11-20 14:03:08 ERROR BasicPropertyAccessor:121 - HHH000123: IllegalArgumentException in class: com.usanin.financedata.entity.QuoteEntity, setter method of property: date
2015-11-20 14:03:08 ERROR BasicPropertyAccessor:122 - HHH000091: Expected type: org.joda.time.DateTime, actual value: java.sql.Timestamp
IllegalArgumentException occurred while calling setter for property [com.usanin.financedata.entity.QuoteEntity.date (expected type = org.joda.time.DateTime)]; target = [com.usanin.financedata.entity.QuoteEntity@7cf3b5ad], property value = [2015-11-11 10:01:00.0]
我还有:Hibernate - 4.3.11.Final 和 org.jadira.usertype:usertype.core:4.0.0.GA
我调整了我的
<bean id="sessionFactory"
.....
<property name="hibernateProperties">
<props>
<prop key="jadira.usertype.autoRegisterUserTypes">true</prop>
...
和实体
...
import org.joda.time.DateTime;
...
@Entity
@Table (name="QUOTE")
public class QuoteEntity {
@Column
private DateTime date;
... getters and setters
【问题讨论】: