Caused by: org.h2.jdbc.JdbcSQLDataException: Hexadecimal string contains non-hex character Caused by: org.h2.jdbc.JdbcSQLDataException: Hexadecimal string contains non-hex character spring spring

Caused by: org.h2.jdbc.JdbcSQLDataException: Hexadecimal string contains non-hex character


Using spring.datasource.url=jdbc:h2:mem:testdb;MODE=MYSQL fixed it for me.

Or adding an annotation @Type to the UUID field should fix the issue:

@Id@Type(type="uuid-char")private UUID user_id;


The actual cause of this problem is the mapping between your object and the generated create table statement by hibernate (ddl-auto:create) used to create your h2 database schema.

If you enable the output of the those ddl statements using:

spring.jpa.properties.hibernate.show_sql=truespring.jpa.properties.hibernate.use_sql_comments=truespring.jpa.properties.hibernate.format_sql=truelogging.level.org.hibernate.type=TRACE

you will most likely see that your UUID class has been mapped to a binary column in your database.

Hibernate:     create table <your_table> (        id bigint generated by default as identity,        ...,        <your_object> binary(255),        ...        primary key (id)    )

This means that your uuid-string is mapped onto a binary column and thus contains illegal characters. You need a varchar(<uuid-length>) column to store a uuid. There are several solution strategies, one of them is defining a type, see this StackOverflow answer. You can read on binary columns on the official MySQL reference site.


I resolved this problem by adding spring.jpa.hibernate.ddl-auto=none to my application.properties file