Spring RestAPI + Postgresql(java.lang.NoClassDefFoundError:org/hibernate/query/BindableType)

rqenqsqc  于 5个月前  发布在  Spring
关注(0)|答案(1)|浏览(63)

我正在开发一个spring应用程序,其目的是从HTTP端点上的传感器接收数据并将其保存在数据库中。最近我需要实现一个使用双数组字段的新实体(VibrationPackage)。在postgres数据库中它是DOUBLE PRECISION[]。
在更新和添加此字段后,我开始收到一条与Hibernate相关的错误消息。我无法找到问题的根源,我需要帮助。
控制台:

.   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.6.3)

2023-12-19 18:16:33.409  INFO 18211 --- [           main] c.brasens.main.SlimmodeApplicationTests  : Starting SlimmodeApplicationTests using Java 17.0.8 on ip-172-31-26-152.us-west-2.compute.internal with PID 18211 (started by ec2-user in /home/ec2-user/mspm-backend)
2023-12-19 18:16:33.412  INFO 18211 --- [           main] c.brasens.main.SlimmodeApplicationTests  : The following profiles are active: prod
2023-12-19 18:16:35.924  INFO 18211 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2023-12-19 18:16:36.088  INFO 18211 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 143 ms. Found 8 JPA repository interfaces.
2023-12-19 18:16:37.529  INFO 18211 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [name: default]
2023-12-19 18:16:37.633  INFO 18211 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate ORM core version 5.6.4.Final
2023-12-19 18:16:38.337  INFO 18211 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2023-12-19 18:16:39.398  INFO 18211 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2023-12-19 18:16:39.440  INFO 18211 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.PostgresPlusDialect
2023-12-19 18:16:39.582  WARN 18211 --- [           main] o.s.w.c.s.GenericWebApplicationContext   : 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]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/hibernate/query/BindableType
2023-12-19 18:16:39.584  INFO 18211 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown initiated...
2023-12-19 18:16:39.709  INFO 18211 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown completed.
2023-12-19 18:16:39.740  INFO 18211 --- [           main] ConditionEvaluationReportLoggingListener :

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2023-12-19 18:16:39.794 ERROR 18211 --- [           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]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/hibernate/query/BindableType
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1804) ~[spring-beans-5.3.15.jar:5.3.15]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:620) ~[spring-beans-5.3.15.jar:5.3.15]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.15.jar:5.3.15]
        at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.15.jar:5.3.15]
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.15.jar:5.3.15]
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.15.jar:5.3.15]
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.15.jar:5.3.15]
        at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1154) ~[spring-context-5.3.15.jar:5.3.15]
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:908) ~[spring-context-5.3.15.jar:5.3.15]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.15.jar:5.3.15]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:732) ~[spring-boot-2.6.3.jar:2.6.3]
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:414) ~[spring-boot-2.6.3.jar:2.6.3]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:302) ~[spring-boot-2.6.3.jar:2.6.3]
        at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:136) ~[spring-boot-test-2.6.3.jar:2.6.3]
        at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99) ~[spring-test-5.3.15.jar:5.3.15]
        at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124) ~[spring-test-5.3.15.jar:5.3.15]
        at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:124) ~[spring-test-5.3.15.jar:5.3.15]
        at org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.java:190) ~[spring-test-5.3.15.jar:5.3.15]
        at org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.java:132) ~[spring-test-5.3.15.jar:5.3.15]
        at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:248) ~[spring-test-5.3.15.jar:5.3.15]
        at org.springframework.test.context.junit.jupiter.SpringExtension.postProcessTestInstance(SpringExtension.java:138) ~[spring-test-5.3.15.jar:5.3.15]
        at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$invokeTestInstancePostProcessors$8(ClassBasedTestDescriptor.java:363) ~[junit-jupiter-engine-5.8.2.jar:5.8.2]
        at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.executeAndMaskThrowable(ClassBasedTestDescriptor.java:368) ~[junit-jupiter-engine-5.8.2.jar:5.8.2]
        at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$invokeTestInstancePostProcessors$9(ClassBasedTestDescriptor.java:363) ~[junit-jupiter-engine-5.8.2.jar:5.8.2]
       
Caused by: java.lang.ClassNotFoundException: org.hibernate.query.BindableType
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641) ~[na:na]
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) ~[na:na]
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525) ~[na:na]
        ... 130 common frames omitted

[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 8.179 s <<< FAILURE! - in com.brasens.main.SlimmodeApplicationTests
[ERROR] contextLoads  Time elapsed: 0.016 s  <<< ERROR!
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/hibernate/query/BindableType
Caused by: java.lang.NoClassDefFoundError: org/hibernate/query/BindableType
Caused by: java.lang.ClassNotFoundException: org.hibernate.query.BindableType

[INFO]
[INFO] Results:
[INFO]
[ERROR] Errors:
[ERROR]   SlimmodeApplicationTests.contextLoads » IllegalState Failed to load Applicatio...
[INFO]
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 25.724 s
[INFO] Finished at: 2023-12-19T18:16:40Z
[INFO] Final Memory: 42M/132M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.2:test (default-test) on project msmp-http: There are test failures.
[ERROR]
[ERROR] Please refer to /home/ec2-user/mspm-backend/target/surefire-reports for the individual test results.
[ERROR] Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

字符串
Maven POM

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.6.3</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.brasens</groupId>
    <artifactId>msmp-http</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>Brasens Backend</name>
    <description>Spring Boot + REST API</description>
    <properties>
        <java.version>17</java.version>
        <spring-cloud.version>2021.0.3</spring-cloud.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>

<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>6.0.2.Final</version>
    <type>pom</type>
</dependency>

<!-- https://mvnrepository.com/artifact/io.hypersistence/hypersistence-utils-hibernate-60 -->
<dependency>
    <groupId>io.hypersistence</groupId>
    <artifactId>hypersistence-utils-hibernate-60</artifactId>
    <version>3.7.0</version>
</dependency>

        <!-- https://mvnrepository.com/artifact/org.postgresql/postgresql -->
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>42.7.1</version>
        </dependency>

        <dependency>
            <groupId>com.auth0</groupId>
            <artifactId>java-jwt</artifactId>
            <version>3.16.0</version>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.24</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <!--
        https://mvnrepository.com/artifact/com.github.wendykierp/JTransforms -->
        <dependency>
            <groupId>com.github.wendykierp</groupId>
            <artifactId>JTransforms</artifactId>
            <version>3.0</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>


我的数据库PostgreSQL:

CREATE TYPE public.maintenance AS ENUM (
    'Predictive', 'Preventive', 'ScheduledCorrective', 'Corrective'
);

CREATE TYPE public.assetstate AS ENUM (
    'WORKING', 'IDLE'
);

CREATE TYPE public.downtimetype AS ENUM (
    'Manual', 'Automatic'
);

CREATE TYPE public.priority AS ENUM (
    'Urgente', 'Alta', 'Media', 'Baixa'
);

CREATE TYPE public.servicetype AS ENUM (
    'Outsourced',
    'Own'
);

CREATE TYPE public.state AS ENUM (
    'COMPLETED', 'PLANNING', 'PROGRESS', 'OPENING'
);

CREATE TYPE public.eventtype AS ENUM (
    'ASSET_DOWN', 'ASSET_UP', 'TEMP_AN', 'VIB_AN'
);

CREATE TABLE client (
    id UUID UNIQUE PRIMARY KEY,
    name VARCHAR(100) NULL,
    email VARCHAR(100) NULL,
    password VARCHAR(60) NOT NULL,
    image_link VARCHAR(100) NULL,
    created_at TIMESTAMP WITHOUT TIME ZONE DEFAULT (now() AT TIME ZONE 'America/Sao_Paulo')
);

CREATE TABLE employee(
    id UUID UNIQUE PRIMARY KEY,
    name VARCHAR(100) NULL,
    email VARCHAR(100) NULL,
    phone VARCHAR(20) NULL,
    image_link VARCHAR(100) NULL,
    created_at TIMESTAMP WITHOUT TIME ZONE DEFAULT (now() AT TIME ZONE 'America/Sao_Paulo')
);

ALTER TABLE employee ADD COLUMN id_client UUID;
ALTER TABLE employee ADD CONSTRAINT fk_client FOREIGN KEY (id_client)
REFERENCES client (id);

CREATE TABLE asset (
    id      UUID                UNIQUE PRIMARY KEY,
    asset_key VARCHAR(50) NULL,
    name VARCHAR(100) NULL,
    manufacturer VARCHAR(100) NULL,
    production_date DATE NULL,
    asset_location VARCHAR(100) NULL,
    asset_model VARCHAR(100) NULL,
    serial_number VARCHAR(100) NULL,
    maintenance_type maintenance NULL,
    downtime    double precision    NULL,
    downtime_type downtimetype NULL,
    asset_state assetstate NULL,
    created_at TIMESTAMP WITHOUT TIME ZONE DEFAULT (now() AT TIME ZONE 'America/Sao_Paulo')
);

ALTER TABLE asset ADD COLUMN id_client UUID;
ALTER TABLE asset ADD CONSTRAINT fk_client FOREIGN KEY (id_client)
REFERENCES client (id);

CREATE TABLE data (
    id      UUID                UNIQUE PRIMARY KEY,

    rms_x           DOUBLE PRECISION    NULL,
    rms_y   double precision    NULL,
    rms_z           DOUBLE PRECISION    NULL,

    temperature double precision    NULL,
    asset_key VARCHAR(50) NULL,
    added TIMESTAMP WITHOUT TIME ZONE DEFAULT (now() AT TIME ZONE 'America/Sao_Paulo'),
    is_analysed BOOLEAN DEFAULT FALSE
);

ALTER TABLE data ADD COLUMN id_asset UUID;
ALTER TABLE data ADD CONSTRAINT fk_asset FOREIGN KEY (id_asset)
REFERENCES asset (id);

CREATE TABLE vibration_package (
    id      UUID                UNIQUE PRIMARY KEY,

    data_array          double precision[]    NULL,

    asset_key VARCHAR(50) NULL,
    added TIMESTAMP WITHOUT TIME ZONE DEFAULT (now() AT TIME ZONE 'America/Sao_Paulo')
);

ALTER TABLE vibration_package ADD COLUMN id_asset UUID;
ALTER TABLE vibration_package ADD CONSTRAINT fk_asset FOREIGN KEY (id_asset)
REFERENCES asset (id);

CREATE TABLE workorder(
    id      UUID                UNIQUE PRIMARY KEY,
    name VARCHAR(100) NULL,
    owner VARCHAR(100) NULL,
    asset_key VARCHAR(100) NULL,
    created_date DATE NULL,
    conclusion_date DATE NULL,
    priority priority NULL,
    maintenance maintenance NULL,
    state state NULL,
    created_at TIMESTAMP WITHOUT TIME ZONE DEFAULT (now() AT TIME ZONE 'America/Sao_Paulo')
);

ALTER TABLE workorder ADD COLUMN id_client UUID;
ALTER TABLE workorder ADD CONSTRAINT fk_client FOREIGN KEY (id_client)
REFERENCES client (id);

CREATE TABLE events(
    id      UUID                UNIQUE PRIMARY KEY,
    event_type eventtype NULL,
    description VARCHAR(100) NULL,
    added TIMESTAMP WITHOUT TIME ZONE
);

ALTER TABLE events ADD COLUMN id_asset UUID;
ALTER TABLE events ADD CONSTRAINT fk_asset FOREIGN KEY (id_asset)
REFERENCES asset (id);

CREATE TABLE perfomaceindex(
    id      UUID                UNIQUE PRIMARY KEY,
    completed   double precision    NULL,
    planning    double precision    NULL,
    progress    double precision    NULL,
    opening double precision    NULL,
    idle    double precision    NULL,
    working double precision    NULL,
    total_downtime  double precision    NULL,

    MP double precision    NULL,
    MPD double precision    NULL,
    runtime_average double precision    NULL,
    MTBF double precision    NULL,
    MTTR double precision    NULL,
    MTTA double precision    NULL,
    availability double precision    NULL
);

ALTER TABLE perfomaceindex ADD COLUMN id_client UUID;
ALTER TABLE perfomaceindex ADD CONSTRAINT fk_client FOREIGN KEY (id_client)
REFERENCES client (id);

CREATE TABLE machineintervals(
    id      UUID                UNIQUE PRIMARY KEY,
    asset_state assetstate NULL,
    added TIMESTAMP WITHOUT TIME ZONE
);

ALTER TABLE machineintervals ADD COLUMN id_asset UUID;
ALTER TABLE machineintervals ADD CONSTRAINT fk_asset FOREIGN KEY (id_asset)
REFERENCES asset (id);


我的VibrationPackage型号:

@Entity
@Table(name = "vibration_package")
@TypeDef(
        name = "list-array",
        typeClass = ListArrayType.class
    )
@Getter @Setter @AllArgsConstructor @NoArgsConstructor
public class VibrationPackage{
    @Id
    @GeneratedValue
    @Column(name = "id", columnDefinition = "uuid", nullable = false, unique = true)
    private UUID id;

    @Column(name = "asset_key", nullable = true)
    public String key;
    
    @Type(type = "list-array")
    @Column(
        name = "data_array",
        columnDefinition = "Double[]"
    )
    public List<Double> dataPackage;
    
    @Column(name = "start", nullable = true)
    int start;
    @Column(name = "end", nullable = true)
    int end;
    
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSSSS'Z'", timezone = "UTC")
    @Column(name = "added", nullable = false)
    private ZonedDateTime added = ZonedDateTime.now();
    
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @OnDelete(action = OnDeleteAction.NO_ACTION)
    @JoinColumn(name = "id_asset", nullable = false)
    @JsonIgnore
    private Asset asset;
    
    @Override
    public String toString() {
        return "VibrationPackage [key=" + key + ", dataPackage=" + dataPackage + ", start=" + start
                + ", end=" + end + "]";
    }

}

6psbrbz9

6psbrbz91#

基本上,我的依赖项中存在某种不兼容性,所以我重做了POM并删除了那里的Hibernate注解,只保留了Spring和hypersistence-utils-hibernate-52。

相关问题