Mikael_K
Mikael_K

Reputation: 33

Using Joda DateTime with Hibernate in H2 Database - SQLError

I'm using JPA - Hibernate 2.1 with Joda DateTime. For DateTime conversion I'm using org.jadira.usertype to work with Hibernate. This works all fine for development and local testing with H2 in-memory DB. But on our Jenkins server the tests always fail with some strange 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:

And:

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:

It's pretty hard to find out why it's working on my laptop and not on the server. The only difference is that the server is running on an Ubuntu VM and I'm using Windows 8.1 - do I need to consider something like e.g. that OpenJDK could cause problem? Or is this a know H2 DB issue - but I could find anything? Any idea why and what I can do to solve it?

Thank you!

The field which causes problem:

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

persistence.xml - JPA properties.

<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>

Upvotes: 3

Views: 3825

Answers (1)

Vlad Mihalcea
Vlad Mihalcea

Reputation: 153780

I think you missed the @Column and the @Type annotations:

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

Upvotes: 6

Related Questions