[英]Can't convert type: value: java.sql.Timestamp to org.joda.time.DateTime
During persist time - all is ok, but when I try to execute next query I will have exception 在持续时间内-一切正常,但是当我尝试执行下一个查询时,我将遇到异常
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();
after execute I get error: 执行后出现错误:
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]
Also I have: Hibernate - 4.3.11.Final, and org.jadira.usertype:usertype.core:4.0.0.GA 我还有:Hibernate-4.3.11.Final和org.jadira.usertype:usertype.core:4.0.0.GA
and I ajusted in my 我调整了我的
<bean id="sessionFactory"
.....
<property name="hibernateProperties">
<props>
<prop key="jadira.usertype.autoRegisterUserTypes">true</prop>
...
and entity 和实体
...
import org.joda.time.DateTime;
...
@Entity
@Table (name="QUOTE")
public class QuoteEntity {
@Column
private DateTime date;
... getters and setters
In this case I have chosen to use entity query like this: 在这种情况下,我选择使用像这样的实体查询:
Query query = sessionFactory.getCurrentSession()
.createSQLQuery("Select * From QUOTE")
.addEntity(QuoteEntity.class);
return query.list();
because, behavior of non-managed entity is very weird 因为,非托管实体的行为很奇怪
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.