简体   繁体   English

无法将类型:值:java.sql.Timestamp转换为org.joda.time.DateTime

[英]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.

相关问题 无法将类型类java.sql.Timestamp转换为类org.joda.time.DateTime - Cannot convert of type class java.sql.Timestamp to class org.joda.time.DateTime 将Joda日期时间字符串转换为Java.Sql.TimeStamp以进行插入 - Convert Joda Date Time String To Java.Sql.TimeStamp for an INSERT 数据截断:错误的日期时间值:org.joda.time.DateTime - Data truncation: Incorrect datetime value: org.joda.time.DateTime 如何转换org.joda.time.DateTime到java.time.ZonedDateTime - How to convert from org.joda.time.DateTime to java.time.ZonedDateTime 将 org.joda.time.DateTime 转换为 java.time.OffsetDateTime 的最佳方法是什么? - What is the best way to convert a org.joda.time.DateTime to a java.time.OffsetDateTime? java org.joda.time.DateTime非法模式 - java org.joda.time.DateTime illegal pattern Java EE:使用IntelliJ和Maven的NoClassDefFoundError org.joda.time.DateTime - Java EE: NoClassDefFoundError org.joda.time.DateTime with IntelliJ and Maven 从org.joda.time.DateTime转换为java.util.Calendar的方法 - Approach to convert from org.joda.time.DateTime to java.util.Calendar 如何解决默认不支持的 Joda 日期/时间类型`org.joda.time.DateTime` - how to resolve Joda date/time type `org.joda.time.DateTime` not supported by default MongoDB jodatime:org.bson.codecs.configuration.CodecConfigurationException:找不到类org.joda.time.DateTime的编解码器 - MongoDB jodatime: org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class org.joda.time.DateTime
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM