Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when running application NoClassDef jakarta/persistance/EntityManager #872

Open
dgeiselmanMOO opened this issue May 2, 2024 · 9 comments

Comments

@dgeiselmanMOO
Copy link

Running Grails 6.2.0, JDK 11, Springboot 2.7.18, Hibernate core 6.4.18, hibernate5 8.1.0, hikari is involved, Gradle 7.6.2

Got through an error with MVCC by upgrading to Hibernate core 6.4.18.Final and now I'm getting an error about jakarta/persistance/EntityManger is not found. What library or setting am I missing?

2024-05-02 15:47:43,927 [main] [] ERROR org.springframework.boot.SpringApplication | parent-span: | trace: | span: |: Application run failed
java.lang.IllegalStateException: Failed to introspect Class [org.grails.orm.hibernate.HibernateDatastore] from ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader@5c29bfd]
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:485)
at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:361)
at org.springframework.util.ReflectionUtils.getUniqueDeclaredMethods(ReflectionUtils.java:418)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.lambda$getTypeForFactoryMethod$2(AbstractAutowireCapableBeanFactory.java:765)
at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1705)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryMethod(AbstractAutowireCapableBeanFactory.java:764)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:703)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:674)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1685)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:570)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:542)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:132)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:756)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:573)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:732)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:409)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:308)
at grails.boot.GrailsApp.run(GrailsApp.groovy:99)
at grails.boot.GrailsApp.run(GrailsApp.groovy:458)
at grails.boot.GrailsApp.run(GrailsApp.groovy:445)
at qwr.Application.main(Application.groovy:11)
Caused by: java.lang.NoClassDefFoundError: jakarta/persistence/EntityManager
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1016)
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174)
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:800)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:698)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:621)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:579)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
at java.base/java.lang.Class.getDeclaredMethods0(Native Method)
at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3166)
at java.base/java.lang.Class.getDeclaredMethods(Class.java:2309)
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:467)
... 21 common frames omitted
Caused by: java.lang.ClassNotFoundException: jakarta.persistence.EntityManager
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 34 common frames omitted

@matrei
Copy link
Contributor

matrei commented May 2, 2024

Grails 6 is not compatible with Hibernate 6.

@dgeiselmanMOO
Copy link
Author

Ok, how do I get around this error from hibernate 5.6.15.Final? This is what I was getting before Hibernate 6.4.18

2024-05-03 07:35:01,564 [main] [] ERROR org.apache.tomcat.jdbc.pool.ConnectionPool | parent-span: | trace: | span: |: Unable to create initial connections of pool.
org.h2.jdbc.JdbcSQLNonTransientConnectionException: Unsupported connection setting "MVCC" [90113-224]

@matrei
Copy link
Contributor

matrei commented May 3, 2024

Can you show your dataSource.url config? The MVCC connection parameter is no longer valid for H2 v2.

@dgeiselmanMOO
Copy link
Author

jdbc:sqlserver://WN4747.corp.mutualofomaha.com;databaseName=QUALITY_WORK_REVIEW

@dgeiselmanMOO
Copy link
Author

MVCC is not in my code at all.

@matrei
Copy link
Contributor

matrei commented May 3, 2024

Ok, but even if you say that "hikari is involved", you have a tomcat jdbc connection pool trying to create a H2 jdbc connection with the MVCC parameter. I cannot say why with the information you have given.

@dgeiselmanMOO
Copy link
Author

dgeiselmanMOO commented May 3, 2024

Any of this help?

Here are the yaml settings

datasource:
    type: com.zaxxer.hikari.HikariDataSource
    driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
    url: jdbc:sqlserver://WN4747.corp.mutualofomaha.com;databaseName=QUALITY_WORK_REVIEW
    username: user
    password: pass
    hikari:
        driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
        data-source-class-name: com.microsoft.sqlserver.jdbc.SQLServerDataSource
        minimum-idle: 5
        idle-timeout: 600000
        maximum-pool-size: 10
        auto-commit: true
        pool-name: HikariCorePool
        max-lifetime: 1800000
        connection-timeout: 30000

hibernate:
default_schema: dbo
enable_lazy_load_no_trans: true
dialect: org.hibernate.dialect.SQLServerDialect
driverClassName: org.h2.Driver
cache:
use_second_level_cache: true
use_query_cache: false
region.factory_class: org.hibernate.cache.ehcache.EhCacheRegionFactory
legacy_limit_handler: true

gradle
configurations {
all*.with {
exclude group: 'log4j'
exclude module: 'xml-apis'
exclude module: 'bcprov-jdk15on'
exclude module: 'bcprov-jdk14'
}
all {
resolutionStrategy {
force 'com.h2database:h2:2.2.224'
force 'io.micronaut.sql:micronaut-sql-bom:5.6.0'
force 'io.micronaut:micronaut-bom:3.10.4'
force 'org.grails:grails-datastore-gorm-hibernate5:8.1.0'
force 'io.micronaut.spring:micronaut-spring-context:5.6.0'
force 'io.micronaut.cache:micronaut-cache-core:4.3.0'
force 'org.apache.tomcat:tomcat-jdbc:11.0.0-M19'

    }
}

}

dependencies {
runtimeOnly "com.bertramlabs.plugins:asset-pipeline-grails:4.3.0"
compileOnly "io.micronaut:micronaut-inject-groovy"
//developmentOnly("org.springframework.boot:spring-boot-devtools")
console "org.grails:grails-console"
implementation "com.mutualofomaha:enterprise-ldap-service-client:4.0.1"

// default dependencies for web app
implementation 'org.springframework.boot:spring-boot-starter'
implementation 'org.springframework.boot:spring-boot-starter-logging'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-autoconfigure'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation "org.springframework.boot:spring-boot-starter-tomcat"

implementation "org.springframework.boot:spring-boot-starter-validation"
implementation 'org.springframework.ldap:spring-ldap-core'
implementation 'com.okta.spring:okta-spring-boot-starter:+'
api 'com.okta.spring:okta-spring-boot-starter:3.0.6'
implementation 'org.grails.plugins:spring-security-oauth2:2.0.0-RC1'
implementation 'com.okta.spring:okta-spring-security-oauth2:3.0.2'
implementation 'com.okta.sdk:okta-sdk-api:8.2.3'
runtimeOnly 'com.okta.sdk:okta-sdk-impl:8.2.3'
runtimeOnly 'com.okta.sdk:okta-sdk-httpclient:8.2.3'

implementation 'org.grails:grails-dependencies'
implementation 'org.grails:grails-web-boot'
implementation 'org.grails.plugins:spring-security-core:5.2.0'
implementation 'org.grails.plugins:spring-security-ldap:4.0.0.M1'
implementation "org.grails:grails-core"
implementation "org.grails:grails-logging"
implementation "org.grails.plugins:scaffolding"
implementation "org.grails.plugins:async"
implementation "org.grails:grails-plugin-rest"
implementation "org.grails:grails-plugin-datasource"
implementation "org.grails:grails-plugin-databinding"
implementation "org.grails:grails-plugin-i18n"
implementation "org.grails:grails-plugin-services"
implementation "org.grails:grails-plugin-url-mappings"
implementation 'org.grails:grails-datastore-gorm-hibernate5:8.1.0'
implementation "org.grails:grails-plugin-interceptors"
implementation ("org.grails.plugins:cache:5.0.1") {
    exclude group: "gradle.plugin.com.github.erdi.webdriver-binaries", module: "webdriver-binaries-gradle-plugin"
}
implementation "org.grails.plugins:export:2.0.0"
implementation "org.grails.plugins:wslite:0.7.2.0"
implementation "org.grails.plugins:events"
implementation "org.grails.plugins:gsp"
profile "org.grails.profiles:web"
testImplementation "org.grails:grails-gorm-testing-support"
testImplementation "org.grails.plugins:geb"
testImplementation "org.grails:grails-web-testing-support"
implementation "org.grails:grails-datastore-test-support:1.0.2-grails-2.4"
implementation "org.grails.plugins:underscore:1.5.2"
implementation "org.grails.plugins:remote-pagination:0.4.8"
implementation "org.grails.plugins:build-test-data:2.4.0"
implementation "org.grails.plugins:ckeditor:4.5.4.1"
implementation "org.grails.plugins:joda-time:1.5"
implementation "org.grails.plugins:quartz:1.0.2"
implementation "org.grails.plugins:csv:0.3.1"
implementation "org.grails.plugins:resources:1.2.14"
implementation "org.grails.plugins:twitter-bootstrap:3.3.5"
implementation "org.grails.plugins:jquery:1.11.1"
implementation "org.grails.plugins:fields:3.0.0.RC1"
implementation "org.grails.plugins:greenmail:1.3.4"
implementation "org.grails.plugins:mail:3.0.0"
implementation 'org.grails.plugins:filterpane:2.4.4'
implementation 'com.zaxxer:HikariCP:5.1.0'

implementation 'org.grails.plugins:hibernate5:8.1.0'
implementation 'org.hibernate:hibernate-core:5.6.15.Final'
implementation "org.hibernate:hibernate-ehcache:5.6.15.Final"
implementation "org.hibernate:hibernate-hikaricp:5.6.15.Final"

implementation "org.grails:gorm-hibernate5-spring-boot:8.1.0"
implementation 'com.github.javaparser:javaparser-core:3.25.2'

implementation 'org.xhtmlrenderer:flying-saucer-pdf:9.5.1'
implementation 'org.xhtmlrenderer:flying-saucer-core:9.5.1'
implementation 'org.grails.plugins:rendering:2.0.3'
implementation 'org.apache.commons:commons-lang3:3.14.0'

compileOnly 'org.springframework:spring-test:5.3.34'
runtimeOnly 'org.grails.plugins:ajax-tags:1.0.0'

testImplementation 'junit:junit:4.13.2'

implementation 'com.mutualofomaha:mutualofomahautilities:6.0.0'
implementation 'com.mutualofomaha.hrp:HRDataServiceClient:2.0.3'
implementation 'com.jscape:sftp:9.0.0'
implementation 'com.microsoft.sqlserver:mssql-jdbc:12.6.0.jre11'
runtimeOnly "com.h2database:h2"
runtimeOnly "org.apache.tomcat:tomcat-jdbc"
implementation group: 'com.googlecode.concurrentlinkedhashmap', name: 'concurrentlinkedhashmap-lru', version: '1.4.2'

implementation 'org.apache.directory.server:apacheds-core:1.5.4'
implementation 'org.apache.directory.server:apacheds-protocol-ldap:1.5.4'
implementation 'org.apache.directory.shared:shared-ldap:0.9.12'
implementation 'org.codehaus.groovy:groovy-dateutil:3.0.14'

implementation "org.apache.httpcomponents:httpclient:+"
implementation 'com.mutualofomaha.afi:cyberark-client:2.0.+'

testImplementation "io.micronaut:micronaut-inject-groovy"
testImplementation "org.seleniumhq.selenium:selenium-remote-driver"
testImplementation "org.seleniumhq.selenium:selenium-api"
testImplementation "org.seleniumhq.selenium:selenium-support"
testRuntimeOnly "org.seleniumhq.selenium:selenium-chrome-driver"
testRuntimeOnly "org.seleniumhq.selenium:selenium-firefox-driver"

}

@dgeiselmanMOO
Copy link
Author

Commenting out runtimeOnly "org.apache.tomcat:tomcat-jdbc" gives this error

2024-05-03 09:40:03,409 [main] [] ERROR org.hibernate.engine.jdbc.spi.SqlExceptionHelper | parent-span: | trace: | span: |: Unsupported connection setting "MVCC" [90113-224]
2024-05-03 09:40:07,884 [main] [] ERROR org.hibernate.engine.jdbc.spi.SqlExceptionHelper | parent-span: | trace: | span: |: Unsupported connection setting "MVCC" [90113-224]
2024-05-03 09:40:07,885 [main] [] ERROR org.springframework.boot.web.embedded.tomcat.TomcatStarter | parent-span: | trace: | span: |: Error starting Tomcat context. Exception: org.springframework.beans.factory.BeanCreationException. Message: Error creating bean with name 'authenticationProcessingFilterDeregistrationBean': Cannot resolve reference to bean 'authenticationProcessingFilter' while setting bean property 'filter'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'authenticationProcessingFilter': Cannot resolve reference to bean 'authenticationManager' while setting bean property 'authenticationManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'authenticationManager': Cannot resolve reference to bean 'daoAuthenticationProvider' while setting constructor argument with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'daoAuthenticationProvider': Cannot resolve reference to bean 'userDetailsService' while setting bean property 'userDetailsService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userDetailsService': Unsatisfied dependency expressed through method 'setTargetDatastore' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateDatastore': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.grails.orm.hibernate.HibernateDatastore]: Constructor threw exception; nested exception is org.hibernate.exception.JDBCConnectionException: Unable to check JDBC Connection auto-commit in preparation for DDL execution
2024-05-03 09:40:07,936 [main] [] WARN org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext | parent-span: | trace: | span: |: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
2024-05-03 09:40:08,017 [main] [] ERROR org.springframework.boot.SpringApplication | parent-span: | trace: | span: |: Application run failed

@matrei
Copy link
Contributor

matrei commented May 4, 2024

It looks like your using the Spring way to declare a datasource (not the Grails way).
Then you also configure hibernate with dialect: org.hibernate.dialect.SQLServerDialect and driverClassName: org.h2.Driver.

I would start with a new project and setup the database connection according to the Grails configuration docs to try and get it working. There is an example of using HikariCP there. Then map that over to your existing application.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants