我正在使用JPA - Hibernate 2.1和Joda DateTime。为了进行DateTime转换,我使用org.jadira.usertype来与Hibernate配合使用。这在使用H2内存数据库进行开发和本地测试时都运行良好。但是在我们的Jenkins服务器上,测试总是会失败,并出现一些奇怪的SQLException。
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虚拟机上,而我使用的是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
注解是问题所在。我原以为 JPA 属性<prop key="jadira.usertype.autoRegisterUserTypes">true</prop>
将替换类型注解。(尽管我认为我也测试过带类型注解的情况,但现在很高兴它正在工作)!非常感谢! - Mikael_Kjadira.usertype.autoRegisterUserTypes=true
在 Hibernate 5.4.23 中适用,但在 5.4.25 中存在问题 https://hibernate.atlassian.net/browse/HHH-14376 - banterCZ