I'm running into a weird dilemma with h2. We have an in memory h2 db setup, mode a la Oracle, to help with our unit tests. We've set the Timezone of the Application as
@PostConstruct
void started() {
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
}
We have our h2 setup as a datasource in our maven/springboot app as below:
datasource.config.url=jdbc:h2:mem:AZ;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;MODE=ORACLE;
datasource.config.username=sa
datasource.config.password=
datasource.config.driver-class-name=org.h2.Driver
And I have a test running that's based around timestamp. So I wrote this little mapper to get the DB time from h2:
@Select("Select CURRENT_TIMESTAMP")
String selectCurrentTimestamp();
The issue is that h2 keeps taking the actual system time of what it's running on instead of listening to the timezone settings laid out above. So inserts in our unit tests insert at the correct time, regardless. But Selects based around time seem to get translated based on the system time and thus don't work properly. I've also made the transition to using newer java 8 java.time classes as params to my select functions etc. Still no dice.
I've read a good few posts around this involving hibernate (not being used explicitly) and a few other slightly similar questions. However I haven't found a solution to this particular problem and could use some help.
Who's really the source of this issue, JDBC? Or H2? And depending on that, how could I start down a track to fix it? Is there a string I can provide to the JDBC connection URL? Or another setting to be made?