繁体   English   中英

在H2数据库中使用Joda DateTime和Hibernate - SQLError

[英]Using Joda DateTime with Hibernate in H2 Database - SQLError

我正在使用JPA - Hibernate 2.1和Joda DateTime。 对于DateTime转换,我使用org.jadira.usertype来使用Hibernate。 这对于使用H2内存数据库的开发和本地测试都很好。 但是在我们的Jenkins服务器上,测试总是因一些奇怪的SQLExceptions而失败。

WARN  o.h.e.jdbc.spi.SqlExceptionHelper - SQL Error: 90003, SQLState: 90003
ERROR o.h.e.jdbc.spi.SqlExceptionHelper - Hexadecimal string with odd number of characters: "2015-01-22 14:15:52.965"; SQL statement:

和:

WARN  o.h.e.jdbc.spi.SqlExceptionHelper - SQL Error: 90004, SQLState: 90004
ERROR o.h.e.jdbc.spi.SqlExceptionHelper - Hexadecimal string contains non-hex character: "2015-01-22 14:15:52.98"; SQL statement:

很难找出为什么它在我的笔记本电脑上运行而不是在服务器上运行。 唯一的区别是服务器在Ubuntu VM上运行而我正在使用Windows 8.1 - 我是否需要考虑类似OpenJDK可能导致问题的问题? 或者这是一个知道的H2 DB问题 - 但我能找到任何东西吗? 知道为什么以及我能做些什么来解决它?

谢谢!

导致问题的领域:

@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)//tried to remove this without success
private DateTime lastSeen;

persistence.xml - JPA属性。

<property name="jpaProperties">
        <props>
            <prop key="hibernate.hbm2ddl.auto">create-drop</prop>
            <prop key="hibernate.show_sql">true</prop>
            <prop key="hibernate.dialect">org.hibernate.dialect.H2Dialect</prop>
            <prop key="hibernate.connection.CharSet">utf-8</prop>
            <prop key="hibernate.connection.characterEncoding">utf-8</prop>
            <prop key="hibernate.connection.useUnicode">true</prop>
            <prop key="hibernate.hbm2ddl.import_files">test-import.sql</prop>
            <prop key="jadira.usertype.autoRegisterUserTypes">true</prop>
        </props>
    </property>

我想你错过了@Column@Type注释:

@Type(type="org.jadira.usertype.dateandtime.joda.PersistentDateTime")
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
private DateTime lastSeen;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM