2

I try to connect to my h2 database. My application.properties is empty. When I try to connect I get the following error message:

Database "mem:/~/test" not found, either pre-create it or allow remote database creation (not recommended in secure environments) [90149-200] 90149/90149

Now I add to my application.properties this line:

spring.jpa.hibernate.ddl-auto=create

Now I get this error message when I try to rerun my Spring application:

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-04-28 23:08:20.102 ERROR 15728 --- [  restartedMain] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

An attempt was made to call a method that does not exist. The attempt was made from the following location:

    org.hibernate.jpa.boot.internal.PersistenceUnitInfoDescriptor.getValidationMode(PersistenceUnitInfoDescriptor.java:88)

The following method did not exist:

    javax.persistence.spi.PersistenceUnitInfo.getValidationMode()Ljavax/persistence/ValidationMode;

The method's class, javax.persistence.spi.PersistenceUnitInfo, is available from the following locations:

    jar:file:/C:/Users/x/.gradle/caches/modules-2/files-2.1/javax.persistence/persistence-api/1.0/5725f57873e05e068803e2bf9d5a8ea3740ffec5/persistence-api-1.0.jar!/javax/persistence/spi/PersistenceUnitInfo.class
    jar:file:/C:/Users/x/.gradle/caches/modules-2/files-2.1/jakarta.persistence/jakarta.persistence-api/2.2.3/8f6ea5daedc614f07a3654a455660145286f024e/jakarta.persistence-api-2.2.3.jar!/javax/persistence/spi/PersistenceUnitInfo.class

It was loaded from the following location:

    file:/C:/Users/x/.gradle/caches/modules-2/files-2.1/javax.persistence/persistence-api/1.0/5725f57873e05e068803e2bf9d5a8ea3740ffec5/persistence-api-1.0.jar


Action:

Correct the classpath of your application so that it contains a single, compatible version of javax.persistence.spi.PersistenceUnitInfo

My build.gradle (dependencies) looks like this:

dependencies {
    compile(group: 'javax.persistence', name: 'persistence-api', version: '1.0')
    compile(group: 'org.apache.directory.api', name: 'api-all', version: '2.0.1')
    compile 'com.h2database:h2'
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-data-rest'
    implementation 'org.springframework.boot:spring-boot-starter-mail'
    implementation 'org.springframework.boot:spring-boot-starter-security'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    compileOnly 'org.projectlombok:lombok'
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    annotationProcessor 'org.projectlombok:lombok'
    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
    testImplementation 'org.springframework.security:spring-security-test'
}

What is wrong?

Thanks

2 Answers 2

2

Add h2 configuration to your application.properties

spring.datasource.url=jdbc:h2:mem:DBNAME
spring.datasource.username=root
spring.datasource.password=SA
spring.datasource.driverClassName=org.h2.Driver
spring.h2.console.enabled=true
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.datasource.initialize=true
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
Sign up to request clarification or add additional context in comments.

Comments

0

I guess that by adding the explicit dependency to compile(group: 'javax.persistence', name: 'persistence-api', version: '1.0') in build.gradle you override the version of the transitive dependency and thus api and implementation are out of sync. Try to remove this dependency.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.