Caused by: org.h2.jdbc.JdbcSQLException: Function "TO_TIMESTAMP" not found; SQL statement: - h2

Can someone help me out here- getting following errors while running DML commands.
Caused by: org.h2.jdbc.JdbcSQLException: Function "TO_TIMESTAMP" not found; SQL statement:

Finally i got this answer, we were using older version of h2 database dependency in our project.
for Quick fixed,Take out latest dependency and add in your pom.xml file.
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.195</version>
</dependency>
http://www.h2database.com/html/download.html
https://mvnrepository.com/artifact/com.h2database/h2

I had a similar exception (org.h2.jdbc.JdbcSQLSyntaxErrorException: Function "TO_TIMESTAMP" not found) when upgrading h2 from 1.4.2 to 2.2.202
I don't know why, but it appears that the function had been removed
To make it work, I replaced to_timestamp by parsedatetime
parsedatetime follow the java.text.SimpleDataFormat semantics
Edit : Another way would be to add compatibity mode to Oracle (Mode=Oracle):
Example in spring boot : https://stackoverflow.com/a/64799048/1546137

Related

Flyway spring boot + java, new local database created by hibernate but now migrate tries to apply migrations that already happened

I initially created my project using hibernate to create tables like most people do, but then following recommendations I started using flyway to do db migrations.
Problem is I erased my entire local system including db and trying to spin it u again but I get conflicts of hibernate and flyway.
I'm using the java api by the way. So when I went to rebuild the database locally I turned on
spring.jpa.hibernate.ddl-auto=${HIBERNATE_DDL:create} just for the first run, then turned it to validate
So it built all the tables, but now when I try to launch the application it will try to run the first migration which is
ALTER TABLE public.auth ADD COLUMN resent boolean
which will cause an error on boot because that new column was added by hibernate
Error Code : 0
Message : ERROR: column "resent" of relation "auth" already exists
Location : db/migration/V1__Add_Resent_To_Auth.sql (/Users/brian/code/slap/build/resources/main/db/migration/V1__Add_Resent_To_Auth.sql)
Line : 1
Statement : ALTER TABLE public.auth
ADD COLUMN resent boolean
So how do I tell flyway that the current version is V9 and only run migrations after that. Shouldn't it just go look at the flyway_schema_history and see version 9 is the last entry then run migrations after that? I must be missing something
I tried doing this in my config to set the baseline version first
#Configuration
class FlyWay() {
#Value("\${spring.datasource.url}")
lateinit var url: String
#Value("\${spring.datasource.username}")
lateinit var username: String
#Value("\${spring.datasource.password}")
lateinit var password: String
#Bean
fun migrate() {
val flyway = Flyway.configure().baselineVersion("9.0").dataSource(url, username, password).load()
flyway.migrate()
}
}
no such luck it still tries to run V1
I tried adding it to application.properties too
spring.flyway.baselineVersion=9.0
same error
Scenario as I understood it:
Tables already exist
State of the tables corresponds to version "9.0"
Flyway baseline version should be set once for the local test DB
It might be useful to set the version via command line, since it is to be applied to the test database only once and then the normal migration strategies are to be applied.
Documentation see: https://flywaydb.org/documentation/usage/commandline/baseline
On macOS the Flyway command line client can be installed with brew install flyway.
Instructions
make sure the table flyway_schema_history is deleted. Use your preferred SQL client:
drop table flyway_schema_history;
then set the baseline version using the Flyway command line client (this example uses a Postgres database):
flyway -user=stephan -password= -url=jdbc:postgresql://localhost:5432/stephan -baselineVersion="9.0" -locations="src/main/resources/db/migration" baseline
check in SQL client:
select version from flyway_schema_history ;
This should show now "9.0". After that, the Spring Boot application should behave as usual.
Test
Alternative
For those people who prefer to do this with a Maven command:
drop the table flyway_schema_history like shown above
use the command mvn flyway:baseline -Dflyway.baselineVersion="9.0" to set the baseline version
This requires a bit of configuration in the pom.xml file, e.g. if using a Postgres database:
<build>
...
<plugins>
...
<plugin>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>7.1.1</version>
<configuration>
<url>jdbc:postgresql://localhost:5432/stephan</url>
<user>stephan</user>
</configuration>
<dependencies>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.18</version>
</dependency>
</dependencies>
</plugin>
...
Test with Maven
A quick test shows the same result.
Why not export the SQL-script from your database (created by Hibernate) and add it as the first Flyway script into your application? It's the cleanest solution as Hibernate doesn't need to be started manually again when the application will run on other systems.
Just try once after adding the following line in your application.yml
spring.flyway.baseline-on-migrate: true

Why documents4j run test with maven occurs error

I using documents4j to convert docx to PDF, while run in IDEA, all is find, but when I run test with maven or jenkins, I got an error:
java.lang.IllegalStateException: Shutdown in progress
at java.base/java.lang.ApplicationShutdownHooks.remove(ApplicationShutdownHooks.java:82) ~[na:na]
at java.base/java.lang.Runtime.removeShutdownHook(Runtime.java:242) ~[na:na]
at com.documents4j.job.ConverterAdapter.deregisterShutdownHook(ConverterAdapter.java:121) ~[documents4j-util-conversion-1.1.5.jar:na]
at com.documents4j.job.ConverterAdapter.cleanUp(ConverterAdapter.java:107) ~[documents4j-util-conversion-1.1.5.jar:na]
at com.documents4j.job.ConverterAdapter.shutDown(ConverterAdapter.java:98) ~[documents4j-util-conversion-1.1.5.jar:na]
at com.documents4j.job.LocalConverter.shutDown(LocalConverter.java:109) ~[documents4j-local-1.1.5.jar:na]
at com.documents4j.job.ConverterAdapter$ConverterShutdownHook.run(ConverterAdapter.java:134) ~[documents4j-util-conversion-1.1.5.jar:na]
My pom.xml like this:
<dependency>
<groupId>com.documents4j</groupId>
<artifactId>documents4j-local</artifactId>
<version>1.1.5</version>
</dependency>
<dependency>
<groupId>com.documents4j</groupId>
<artifactId>documents4j-transformer-msoffice-word</artifactId>
<version>1.1.5</version>
</dependency>
I assume that Maven runs tests in parallel (to maybe even an already running converter), what does not work. MS Word needs to run as a singleton. I do not recommend to fire up the converter within one.
Same issue and I solved it.
The problem because you create new Docx file and convert it to Pdf at the same time (in the same action).
It works well if the Docx file it exists before you convert it.

javax.validation.BootstrapConfiguration.getClockProviderClassName()Ljava/lang/String No such method

I am getting below exception while executing springboot application:
Caused by: java.lang.NoSuchMethodError: 'javax.validation.BootstrapConfiguration.getClockProviderClassName()Ljava/lang/String;
at org.hibernate.validator.internal.xml.ValidationBootstrapParameters.<init>(ValidationBootstrapParameters.java:63) ~[hibernate-validator-6.0.7.Final.jar!/:6.0.7.Final]'
I included validation-api as a dependency with latest version & also made sure no other version is coming (not using hibernate validator as well) Still it is failing. Please suggest any solution.
Check the lib folder to differing version of validation-api -- for example
jakarta.validation-api-2.0.2.jar
validation-api-1.1.0.Final.jar
And try to see if you can remove validation-api-1.1.0.Final.jar

ignite-indexing and H2 version

When I use the spatial index module in ignite1.6.0 , I found it depends 1.3.175 version of the H2, but I need to use the 1.4.X h2 version.
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.3.175</version>
<scope>compile</scope>
</dependency>
This method org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing # start will call org.h2.constant.SysProperties and org.h2.util.Utils, in front of the class in the 1.3.176 version of the above have been It does not exist, the latter class is missing serializer variables.
if (SysProperties.serializeJavaObject) {
U.warn(log, "Serialization of Java objects in H2 was enabled.");
SysProperties.serializeJavaObject = false;
}
if (Utils.serializer != null)
U.warn(log, "Custom H2 serialization is already configured, will override.");
Utils.serializer = h2Serializer();
Is there any way to solve it?
Ignite depends on H2 1.3.175 and you can't use any other version. If you already have some code that depends on 1.4, you should isolate Ignite-related code in a separate module in your project. This way different versions of H2 will coextist.

Always getting exception "Wrong type at constant pool index" with Cucumber-Java8

I am trying to set-up an example project for the Java8 dialect of Cucumber. My problem is, that I don't get it running. I always get the following hierarchy of exceptions:
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.068 sec <<< FAILURE! - in soy.wimmer.CucumberIT
Feature: Cucumber with Java8 Time elapsed: 0.051 sec <<< ERROR!
cucumber.runtime.CucumberException: Failed to instantiate class soy.wimmer.CucumberStepdefs
[…]
Caused by: java.lang.reflect.InvocationTargetException: null
[…]
Caused by: cucumber.runtime.CucumberException: java.lang.IllegalArgumentException: Wrong type at constant pool index
[…]
Caused by: java.lang.IllegalArgumentException: Wrong type at constant pool index
at sun.reflect.ConstantPool.getMemberRefInfoAt0(Native Method)
at sun.reflect.ConstantPool.getMemberRefInfoAt(ConstantPool.java:47)
at cucumber.runtime.java8.ConstantPoolTypeIntrospector.getTypeString(ConstantPoolTypeIntrospector.java:37)
at cucumber.runtime.java8.ConstantPoolTypeIntrospector.getGenericTypes(ConstantPoolTypeIntrospector.java:27)
at cucumber.runtime.java.Java8StepDefinition.<init>(Java8StepDefinition.java:45)
at cucumber.runtime.java.JavaBackend.addStepDefinition(JavaBackend.java:162)
at cucumber.api.java8.En.Given(En.java:190)
at soy.wimmer.CucumberStepdefs.<init>(CucumberStepdefs.java:8)
[…]
Results :
Tests in error:
Failed to instantiate class soy.wimmer.CucumberStepdefs
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0
I have no clue why I get this error nor how to fix it.
I have packaged everything in a Maven project. The layout is like that:
./src/test/java/soy/wimmer/CucumberIT.java
./src/test/java/soy/wimmer/CucumberStepdefs.java
./src/test/resources/cucumber/cucumber-java8.feature
./pom.xml
The dependencies I include in the pom.xml are:
<dependencies>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java8</artifactId>
<version>1.2.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.2.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
Additionally the pom.xml only loads the compiler and the failsafe plugin.
My definition of CucumberIT.java:
package soy.wimmer;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;
#RunWith(Cucumber.class)
#CucumberOptions(features = "classpath:cucumber")
public class CucumberIT {
}
My feature definition:
Feature: Cucumber with Java8
As a developer
I want to use Cucumber-java8
So that I have nicer step definitions
Scenario: Let's try it
Given I have some dummy code
When I try to test it
Then it should work with cucumber-java8
And this are my step definitions:
package soy.wimmer;
import cucumber.api.PendingException;
import cucumber.api.java8.En;
public class CucumberStepdefs implements En {
public CucumberStepdefs() {
Given("^I have some dummy code$", () -> {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
});
When("^I try to test it$", () -> {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
});
Then("^it should work with cucumber-java(\\d+)$", (Integer arg1) -> {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
});
}
}
Any idea what I'm doing wrong here?
The problem is caused because the Java8 dialect of Cucumber uses implementation details of Oracle's JDK8.
I was using OpenJDK8 as packaged by Debian which causes a different organisation of the constant pool. When I try the same with Oracle's JDK8 everything works as expected.
If you want to try it yourself, I published the complete example project on github: https://github.com/mawis/cucumber-java8-test
I also reported a bug at the issue tracker of cucumber-jvm here: https://github.com/cucumber/cucumber-jvm/issues/912
You might check the issue tracker to see if the problem will have been fixed in the future.
For now if you want to use cucumber-java8 it seems you have to use Oracle's implementation of the JDK.
(The fame for solving this problem belongs to Holger with his comments to the question. I just wanted to write this answer as a summary.)
Just use 1.2.5 version which has been recently released. It solved the bug referenced by accepted answer.

Resources