Change H2 compatibility mode attribute only

54 views Asked by At

I am using H2 in the (default) REGULAR compatibility mode, but to make it compatible with some DBMS systems that I use simultaneously, I'd like to set ONLY the attribute zeroExLiteralsAreBinaryStrings (MODE and its attributes).

Is there a way to change it without having to set a MODE on the connection string?

I know that changing MODE to MySQL would set this attribute, but on my case it affects other places and system breaks due to other reasons.

What I've tried so far:

  • setting the compatibility MODE to some other enums; Other enums set other undesired flags

  • getting hibernate objects to reach that attribute and set it accordingly; I couldn't reach that attribute specifically

  • checking the H2 database to change it programmatically; SETTINGS table only differs in MODE value. There isn't a zeroExLiteralsAreBinaryStrings stored value.

  • create a new Mode / extend Mode; org.h2.engine.Mode constructor has private access

1

There are 1 answers

0
osmarcf On

I managed to make it work unwrapping the Connection object and reaching inner H2 settings:

// I already had Connection connection
JdbcConnection h2Connection = connection.unwrap(JdbcConnection.class);

h2Connection.getSession().getDynamicSettings().mode.zeroExLiteralsAreBinaryStrings = false;
System.out.println(h2Connection.getSession().getDynamicSettings().mode.zeroExLiteralsAreBinaryStrings);

h2Connection.getSession().getDynamicSettings().mode.zeroExLiteralsAreBinaryStrings = true;
System.out.println(h2Connection.getSession().getDynamicSettings().mode.zeroExLiteralsAreBinaryStrings);