jhipster / generator-jhipster

JHipster is a development platform to quickly generate, develop, & deploy modern web applications & microservice architectures.
https://www.jhipster.tech
Apache License 2.0
21.5k stars 4.02k forks source link

Issue with v8.1.0 when running on docker throws [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: BEFORE_TRANSACTION_COMPLETION #25237

Closed shuoros closed 5 months ago

shuoros commented 7 months ago
Overview of the issue

Hello! I cannot run applications that have been generated with JHipster 8.1.0 on my Ubuntu with generated docker-compose configurations.

The full stack trace:


2024-02-17T14:34:54.159Z  INFO 1 --- [           main] tech.siloxa.subinja.SubinjaApp           : Starting SubinjaApp using Java 17.0.10 with PID 1 (/app/classes started by ? in /)
2024-02-17T14:34:54.165Z  INFO 1 --- [           main] tech.siloxa.subinja.SubinjaApp           : The following 2 profiles are active: "prod", "api-docs"
2024-02-17T14:34:59.191Z  INFO 1 --- [           main] t.siloxa.subinja.config.WebConfigurer    : Web application configuration, using profiles: prod
2024-02-17T14:34:59.194Z  INFO 1 --- [           main] t.siloxa.subinja.config.WebConfigurer    : Web application fully configured
Running Changeset: config/liquibase/changelog/00000000000000_initial_schema.xml::00000000000000::jhipster
Running Changeset: config/liquibase/changelog/00000000000000_initial_schema.xml::00000000000001::jhipster
Running Changeset: config/liquibase/changelog/20240127140943-subtitle.xml::20240127140943-1::soroush
Running Changeset: config/liquibase/changelog/20240127140943-subtitle.xml::20240127140943-2::soroush
Running Changeset: config/liquibase/changelog/20240204100820-scrapException.xml::20240204100820-1::soroush
Liquibase: Update has been successful. Rows affected: 5
2024-02-17T14:35:02.586Z  WARN 1 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: BEFORE_TRANSACTION_COMPLETION
2024-02-17T14:35:02.635Z  INFO 1 --- [           main] .s.b.a.l.ConditionEvaluationReportLogger :

Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
2024-02-17T14:35:02.659Z ERROR 1 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: BEFORE_TRANSACTION_COMPLETION
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1775)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:601)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:523)
        at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:325)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:323)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
        at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1173)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:936)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:616)
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146)
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:753)
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:455)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:323)
        at tech.siloxa.subinja.SubinjaApp.main(SubinjaApp.java:70)
Caused by: java.lang.NoSuchFieldError: BEFORE_TRANSACTION_COMPLETION
        at org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode.<clinit>(PhysicalConnectionHandlingMode.java:50)
        at org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter.buildJpaPropertyMap(HibernateJpaVendorAdapter.java:162)
        at org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter.getJpaPropertyMap(HibernateJpaVendorAdapter.java:132)
        at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:365)
        at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:352)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1822)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1771)
        ... 14 common frames omitted
Related issues

I have done some research on the issue on the internet and some people said that this issue is because of an incompatible version of Jpa in pom.xml:

https://stackoverflow.com/a/6295930/11121568

https://stackoverflow.com/a/5727643/11121568

https://stackoverflow.com/a/70471064/11121568

JHipster Version(s)

8.1.0

JHipster configuration
Welcome to JHipster v8.1.0

Welcome to the JHipster Information Sub-Generator

subinja@0.0.0 /home/soroush/subinja
└── (empty)

##### **JHipster configuration, a `.yo-rc.json` file generated in the root folder**

<details>
<summary>.yo-rc.json file</summary>
<pre>
{
  "generator-jhipster": {
    "applicationType": "monolith",
    "authenticationType": "jwt",
    "baseName": "subinja",
    "buildTool": "maven",
    "cacheProvider": "ehcache",
    "clientFramework": "no",
    "clientTestFrameworks": null,
    "clientTheme": null,
    "creationTimestamp": 1705499553227,
    "databaseType": "sql",
    "devDatabaseType": "postgresql",
    "enableGradleEnterprise": null,
    "enableHibernateCache": true,
    "enableSwaggerCodegen": false,
    "enableTranslation": false,
    "entities": [],
    "feignClient": false,
    "gradleEnterpriseHost": null,
    "jhipsterVersion": "8.1.0",
    "messageBroker": false,
    "microfrontend": null,
    "microfrontends": [],
    "nativeLanguage": "fa",
    "packageName": "tech.siloxa.subinja",
    "prodDatabaseType": "postgresql",
    "reactive": false,
    "searchEngine": false,
    "serverPort": null,
    "serverSideOptions": [],
    "serviceDiscoveryType": false,
    "skipClient": true,
    "testFrameworks": [],
    "websocket": false,
    "withAdminUi": null
  }
}
</pre>
</details>

##### **Environment and Tools**

java version "17.0.9" 2023-10-17 LTS
Java(TM) SE Runtime Environment (build 17.0.9+11-LTS-201)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.9+11-LTS-201, mixed mode, sharing)

git version 2.43.2

node: v18.19.1
npm: 10.4.0

Docker version 25.0.3, build 4debf41

##### **JDL for the Entity configuration(s) `entityName.json` files generated in the `.jhipster` directory**

<details>
<summary>JDL entity definitions</summary>

<pre>
entity Subtitle {
  view Long
  isIndexed Boolean
  inProgress Boolean
  category Category
  url String
  name String
  fullName String
  imdb String
  description String
  date Instant
}
entity ScrapException {
  exception String
}
enum Category {
  MOVIE
  SERIE
}

search Subtitle, ScrapException with no

</pre>
</details>

Congratulations, JHipster execution is complete!
If you find JHipster useful consider sponsoring the project https://www.jhipster.tech/sponsors/

Thanks for using JHipster!
Browsers and Operating System

Ubuntu 22.04.4 LTS (GNU/Linux 5.15.0-94-generic x86_64)

github-actions[bot] commented 7 months ago

JHipster has completed the sample check .yo-rc.json: valid Entities JDL: valid Application: successfully generated Frontend check: success Backend check: success E2E check: success

This check uses jhipster info output from the issue description to generate the sample. Bug report that does not contain this information will be marked as invalid.

kevintanhongann commented 7 months ago

@shuoros if you have any suggested fix, would be great, thanks.

kevintanhongann commented 7 months ago

I believe you were running the spring boot app on Docker, yes? @shuoros

https://github.com/jhipster/generator-jhipster/issues/24469

mshima commented 7 months ago

We need reproduction steps. CI is passing with provided sample.

shuoros commented 7 months ago

@shuoros if you have any suggested fix, would be great, thanks.

Actually, I have no idea how to solve this I tried so many things and even reinstalled the OS and Java and hipster and docker and everything and nothing worked for me!

I believe you were running the spring boot app on Docker. @shuoros

24469

Yes I am trying to run my application on the docker

shuoros commented 7 months ago

We need reproduction steps. CI is passing with provided sample.

Which reproduction step do you need exactly?

I generated a Jhipster application with jhipster command.

Then I build the application with : npm run java:docker output:

> subinja@0.0.0 java:docker
> ./mvnw -ntp verify -DskipTests -Pprod jib:dockerBuild

[INFO] Scanning for projects...
[INFO]
[INFO] --------------------< tech.siloxa.subinja:subinja >---------------------
[INFO] Building Subinja 0.2.5
[INFO]   from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- enforcer:3.4.1:enforce (enforce-versions) @ subinja ---
[INFO] Rule 0: org.apache.maven.enforcer.rules.version.RequireMavenVersion passed
[INFO] Rule 1: org.apache.maven.enforcer.rules.version.RequireJavaVersion passed
[INFO]
[INFO] --- enforcer:3.4.1:enforce (enforce-dependencyConvergence) @ subinja ---
[WARNING] Rule 0: org.apache.maven.enforcer.rules.dependency.DependencyConvergence failed with message:
Failed while enforcing releasability.

Dependency convergence error for javax.xml.bind:jaxb-api:jar:2.3.1 paths to dependency are:
+-tech.siloxa.subinja:subinja:jar:0.2.5
  +-org.liquibase:liquibase-core:jar:4.24.0:compile
    +-javax.xml.bind:jaxb-api:jar:2.3.1:compile
and
+-tech.siloxa.subinja:subinja:jar:0.2.5
  +-com.vladmihalcea:hibernate-types-60:jar:2.21.1:compile
    +-javax.xml.bind:jaxb-api:jar:2.3.0:compile

[INFO]
[INFO] --- resources:3.3.1:copy-resources (config-resources) @ subinja ---
[INFO] Copying 4 resources from src/main/resources to target/classes
[INFO]
[INFO] --- properties:1.2.1:read-project-properties (default) @ subinja ---
[INFO] Loading 22 properties from File: /home/soroush/subinja/sonar-project.properties
[INFO]
[INFO] --- jacoco:0.8.11:prepare-agent (pre-unit-tests) @ subinja ---
[INFO] argLine set to -javaagent:/home/soroush/.m2/repository/org/jacoco/org.jacoco.agent/0.8.11/org.jacoco.agent-0.8.11-runtime.jar=destfile=/home/soroush/subinja/target/jacoco.exec -Djava.security.egd=file:/dev/./urandom -Xmx1G
[INFO]
[INFO] --- git-commit-id:7.0.0:revision (default) @ subinja ---
[INFO]
[INFO] --- spotless:2.41.1:apply (spotless) @ subinja ---
[INFO] Spotless.Java is keeping 99 files clean - 0 were changed to be clean, 0 were already clean, 99 were skipped because caching determined they were already clean
[INFO]
[INFO] --- spring-boot:3.2.1:build-info (default) @ subinja ---
[INFO]
[INFO] --- resources:3.3.1:resources (default-resources) @ subinja ---
[INFO] Copying 51 resources from src/main/resources to target/classes
[INFO]
[INFO] --- compiler:3.11.0:compile (default-compile) @ subinja ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- resources:3.3.1:testResources (default-testResources) @ subinja ---
[INFO] Copying 12 resources from src/test/resources to target/test-classes
[INFO]
[INFO] --- compiler:3.11.0:testCompile (default-testCompile) @ subinja ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- surefire:3.2.2:test (default-test) @ subinja ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- jacoco:0.8.11:report (post-unit-test) @ subinja ---
[INFO] Skipping JaCoCo execution due to missing execution data file.
[INFO]
[INFO] --- jar:3.3.0:jar (default-jar) @ subinja ---
[INFO] Building jar: /home/soroush/subinja/target/subinja-0.2.5.jar
[INFO]
[INFO] --- spring-boot:3.2.1:repackage (default) @ subinja ---
[INFO] Replacing main artifact /home/soroush/subinja/target/subinja-0.2.5.jar with repackaged archive, adding nested dependencies in BOOT-INF/.
[INFO] The original artifact has been renamed to /home/soroush/subinja/target/subinja-0.2.5.jar.original
[INFO]
[INFO] --- jacoco:0.8.11:prepare-agent-integration (pre-integration-tests) @ subinja ---
[INFO] argLine set to -javaagent:/home/soroush/.m2/repository/org/jacoco/org.jacoco.agent/0.8.11/org.jacoco.agent-0.8.11-runtime.jar=destfile=/home/soroush/subinja/target/jacoco-it.exec -Djava.security.egd=file:/dev/./urandom -Xmx1G
[INFO]
[INFO] --- failsafe:3.2.2:integration-test (integration-test) @ subinja ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- jacoco:0.8.11:report-integration (post-integration-tests) @ subinja ---
[INFO] Skipping JaCoCo execution due to missing execution data file.
[INFO]
[INFO] --- checkstyle:3.3.1:check (default) @ subinja ---
[INFO] You have 0 Checkstyle violations.
[INFO]
[INFO] --- failsafe:3.2.2:verify (verify) @ subinja ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- jib:3.4.0:dockerBuild (default-cli) @ subinja ---
[INFO]
[INFO] Containerizing application to Docker daemon as subinja...
[WARNING] Base image 'eclipse-temurin:17-jre-focal' does not use a specific image digest - build may not be reproducible
[INFO] The base image requires auth. Trying again for eclipse-temurin:17-jre-focal...
[INFO] Using base image with digest: sha256:4cb9915fc46edcfc722eba74a905fe848405d1d35d002f62246a123a63f87e7b
[INFO]
[INFO] Container entrypoint set to [bash, -c, /entrypoint.sh]
[INFO]
[INFO] Built image to Docker daemon as subinja
[INFO] Executing tasks:
[INFO] [==============================] 100.0% complete
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  21.088 s
[INFO] Finished at: 2024-02-21T17:38:47Z
[INFO] ------------------------------------------------------------------------

Then I run the application with: docker compose -f src/main/docker/app.yml up -d output:

[+] Running 2/2
 ✔ Container subinja-postgresql-1  Healthy                                                                                                                                                                    0.1s
✔ Container subinja-app-1         Started

docker logs -f subinja-app-1 output:

2024-02-21T17:42:49.365Z  INFO 1 --- [           main] tech.siloxa.subinja.SubinjaApp           : Starting SubinjaApp using Java 17.0.10 with PID 1 (/app/classes started by ? in /)
2024-02-21T17:42:49.380Z  INFO 1 --- [           main] tech.siloxa.subinja.SubinjaApp           : The following 2 profiles are active: "prod", "api-docs"
2024-02-21T17:42:55.838Z  INFO 1 --- [           main] t.siloxa.subinja.config.WebConfigurer    : Web application configuration, using profiles: prod
2024-02-21T17:42:55.841Z  INFO 1 --- [           main] t.siloxa.subinja.config.WebConfigurer    : Web application fully configured
Running Changeset: config/liquibase/changelog/00000000000000_initial_schema.xml::00000000000000::jhipster
Running Changeset: config/liquibase/changelog/00000000000000_initial_schema.xml::00000000000001::jhipster
Running Changeset: config/liquibase/changelog/20240127140943-subtitle.xml::20240127140943-1::soroush
Running Changeset: config/liquibase/changelog/20240127140943-subtitle.xml::20240127140943-2::soroush
Running Changeset: config/liquibase/changelog/20240204100820-scrapException.xml::20240204100820-1::soroush
Liquibase: Update has been successful. Rows affected: 5
2024-02-21T17:43:00.165Z  WARN 1 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: BEFORE_TRANSACTION_COMPLETION
2024-02-21T17:43:00.231Z  INFO 1 --- [           main] .s.b.a.l.ConditionEvaluationReportLogger :

Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
2024-02-21T17:43:00.258Z ERROR 1 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: BEFORE_TRANSACTION_COMPLETION
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1775)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:601)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:523)
        at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:325)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:323)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
        at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1173)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:936)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:616)
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146)
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:753)
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:455)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:323)
        at tech.siloxa.subinja.SubinjaApp.main(SubinjaApp.java:70)
Caused by: java.lang.NoSuchFieldError: BEFORE_TRANSACTION_COMPLETION
        at org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode.<clinit>(PhysicalConnectionHandlingMode.java:50)
        at org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter.buildJpaPropertyMap(HibernateJpaVendorAdapter.java:162)
        at org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter.getJpaPropertyMap(HibernateJpaVendorAdapter.java:132)
        at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:365)
        at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:352)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1822)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1771)

image docker compose files: app.yml:

# This configuration is intended for development purpose, it's **your** responsibility to harden it for production
name: subinja
services:
    app:
        image: subinja
        environment:
            - _JAVA_OPTIONS=-Xmx512m -Xms256m
            - SPRING_PROFILES_ACTIVE=prod,api-docs
            - MANAGEMENT_PROMETHEUS_METRICS_EXPORT_ENABLED=true
            - SPRING_DATASOURCE_URL=jdbc:postgresql://postgresql:5432/subinja
            - SPRING_LIQUIBASE_URL=jdbc:postgresql://postgresql:5432/subinja
        ports:
            - 127.0.0.1:8080:8080
        volumes:
            - /opt/subinja:/opt/subinja
        healthcheck:
            test:
                - CMD
                - curl
                - -f
                - http://localhost:8080/management/health
            interval: 5s
            timeout: 5s
            retries: 40
        depends_on:
            postgresql:
                condition: service_healthy
    postgresql:
        extends:
            file: ./postgresql.yml
            service: postgresql

postgresql.yml:

# This configuration is intended for development purpose, it's **your** responsibility to harden it for production
name: subinja
services:
    postgresql:
        image: postgres:16.1
        volumes:
            - ~/volumes/jhipster/subinja/postgresql/:/var/lib/postgresql/data/
        environment:
            - POSTGRES_DB=**
            - POSTGRES_USER=**
            - POSTGRES_PASSWORD=**
        healthcheck:
            test: ['CMD-SHELL', 'pg_isready -U $${POSTGRES_USER}']
            interval: 5s
            timeout: 5s
            retries: 10
        # If you want to expose these ports outside your dev PC,
        # remove the "127.0.0.1:" prefix
        ports:
            - 127.0.0.1:5432:5432
hoomb commented 7 months ago

We also had the same problem and returned to JHipster 7.9.4, as we couldn't resolve it by changing the dependency versions. There is definitely a huge Problem with JHipster 8 and Docker

mshima commented 5 months ago

JHipster 8.3.0 dependency management was reworked and uses spring-boot-parent now. Dependencies should be easier to customize using spring-boot-parent properties. Closing.