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

rqenqsqc  于 2024-01-05  发布在  Spring
关注(0)|答案(1)|浏览(164)

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

  1. . ____ _ __ _ _
  2. /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
  3. ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
  4. \\/ ___)| |_)| | | | | || (_| | ) ) ) )
  5. ' |____| .__|_| |_|_| |_\__, | / / / /
  6. =========|_|==============|___/=/_/_/_/
  7. :: Spring Boot :: (v2.6.3)
  8. 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)
  9. 2023-12-19 18:16:33.412 INFO 18211 --- [ main] c.brasens.main.SlimmodeApplicationTests : The following profiles are active: prod
  10. 2023-12-19 18:16:35.924 INFO 18211 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
  11. 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.
  12. 2023-12-19 18:16:37.529 INFO 18211 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
  13. 2023-12-19 18:16:37.633 INFO 18211 --- [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.6.4.Final
  14. 2023-12-19 18:16:38.337 INFO 18211 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
  15. 2023-12-19 18:16:39.398 INFO 18211 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
  16. 2023-12-19 18:16:39.440 INFO 18211 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.PostgresPlusDialect
  17. 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
  18. 2023-12-19 18:16:39.584 INFO 18211 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
  19. 2023-12-19 18:16:39.709 INFO 18211 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
  20. 2023-12-19 18:16:39.740 INFO 18211 --- [ main] ConditionEvaluationReportLoggingListener :
  21. Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
  22. 2023-12-19 18:16:39.794 ERROR 18211 --- [ main] o.s.boot.SpringApplication : Application run failed
  23. 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
  24. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1804) ~[spring-beans-5.3.15.jar:5.3.15]
  25. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:620) ~[spring-beans-5.3.15.jar:5.3.15]
  26. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.15.jar:5.3.15]
  27. at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.15.jar:5.3.15]
  28. at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.15.jar:5.3.15]
  29. at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.15.jar:5.3.15]
  30. at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.15.jar:5.3.15]
  31. at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1154) ~[spring-context-5.3.15.jar:5.3.15]
  32. at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:908) ~[spring-context-5.3.15.jar:5.3.15]
  33. at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.15.jar:5.3.15]
  34. at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:732) ~[spring-boot-2.6.3.jar:2.6.3]
  35. at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:414) ~[spring-boot-2.6.3.jar:2.6.3]
  36. at org.springframework.boot.SpringApplication.run(SpringApplication.java:302) ~[spring-boot-2.6.3.jar:2.6.3]
  37. at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:136) ~[spring-boot-test-2.6.3.jar:2.6.3]
  38. at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99) ~[spring-test-5.3.15.jar:5.3.15]
  39. at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124) ~[spring-test-5.3.15.jar:5.3.15]
  40. at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:124) ~[spring-test-5.3.15.jar:5.3.15]
  41. at org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.java:190) ~[spring-test-5.3.15.jar:5.3.15]
  42. at org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.java:132) ~[spring-test-5.3.15.jar:5.3.15]
  43. at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:248) ~[spring-test-5.3.15.jar:5.3.15]
  44. at org.springframework.test.context.junit.jupiter.SpringExtension.postProcessTestInstance(SpringExtension.java:138) ~[spring-test-5.3.15.jar:5.3.15]
  45. at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$invokeTestInstancePostProcessors$8(ClassBasedTestDescriptor.java:363) ~[junit-jupiter-engine-5.8.2.jar:5.8.2]
  46. at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.executeAndMaskThrowable(ClassBasedTestDescriptor.java:368) ~[junit-jupiter-engine-5.8.2.jar:5.8.2]
  47. at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$invokeTestInstancePostProcessors$9(ClassBasedTestDescriptor.java:363) ~[junit-jupiter-engine-5.8.2.jar:5.8.2]
  48. Caused by: java.lang.ClassNotFoundException: org.hibernate.query.BindableType
  49. at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641) ~[na:na]
  50. at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) ~[na:na]
  51. at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525) ~[na:na]
  52. ... 130 common frames omitted
  53. [ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 8.179 s <<< FAILURE! - in com.brasens.main.SlimmodeApplicationTests
  54. [ERROR] contextLoads Time elapsed: 0.016 s <<< ERROR!
  55. java.lang.IllegalStateException: Failed to load ApplicationContext
  56. 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
  57. Caused by: java.lang.NoClassDefFoundError: org/hibernate/query/BindableType
  58. Caused by: java.lang.ClassNotFoundException: org.hibernate.query.BindableType
  59. [INFO]
  60. [INFO] Results:
  61. [INFO]
  62. [ERROR] Errors:
  63. [ERROR] SlimmodeApplicationTests.contextLoads » IllegalState Failed to load Applicatio...
  64. [INFO]
  65. [ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0
  66. [INFO]
  67. [INFO] ------------------------------------------------------------------------
  68. [INFO] BUILD FAILURE
  69. [INFO] ------------------------------------------------------------------------
  70. [INFO] Total time: 25.724 s
  71. [INFO] Finished at: 2023-12-19T18:16:40Z
  72. [INFO] Final Memory: 42M/132M
  73. [INFO] ------------------------------------------------------------------------
  74. [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.
  75. [ERROR]
  76. [ERROR] Please refer to /home/ec2-user/mspm-backend/target/surefire-reports for the individual test results.
  77. [ERROR] Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
  78. [ERROR] -> [Help 1]
  79. [ERROR]
  80. [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
  81. [ERROR] Re-run Maven using the -X switch to enable full debug logging.
  82. [ERROR]
  83. [ERROR] For more information about the errors and possible solutions, please read the following articles:
  84. [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

字符串
Maven POM

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  5. <modelVersion>4.0.0</modelVersion>
  6. <parent>
  7. <groupId>org.springframework.boot</groupId>
  8. <artifactId>spring-boot-starter-parent</artifactId>
  9. <version>2.6.3</version>
  10. <relativePath /> <!-- lookup parent from repository -->
  11. </parent>
  12. <groupId>com.brasens</groupId>
  13. <artifactId>msmp-http</artifactId>
  14. <version>0.0.1-SNAPSHOT</version>
  15. <name>Brasens Backend</name>
  16. <description>Spring Boot + REST API</description>
  17. <properties>
  18. <java.version>17</java.version>
  19. <spring-cloud.version>2021.0.3</spring-cloud.version>
  20. </properties>
  21. <dependencies>
  22. <dependency>
  23. <groupId>org.springframework.boot</groupId>
  24. <artifactId>spring-boot-starter-web</artifactId>
  25. </dependency>
  26. <dependency>
  27. <groupId>org.springframework.boot</groupId>
  28. <artifactId>spring-boot-starter-data-jpa</artifactId>
  29. </dependency>
  30. <dependency>
  31. <groupId>org.springframework.boot</groupId>
  32. <artifactId>spring-boot-starter-security</artifactId>
  33. </dependency>
  34. <!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
  35. <dependency>
  36. <groupId>org.hibernate</groupId>
  37. <artifactId>hibernate-core</artifactId>
  38. <version>6.0.2.Final</version>
  39. <type>pom</type>
  40. </dependency>
  41. <!-- https://mvnrepository.com/artifact/io.hypersistence/hypersistence-utils-hibernate-60 -->
  42. <dependency>
  43. <groupId>io.hypersistence</groupId>
  44. <artifactId>hypersistence-utils-hibernate-60</artifactId>
  45. <version>3.7.0</version>
  46. </dependency>
  47. <!-- https://mvnrepository.com/artifact/org.postgresql/postgresql -->
  48. <dependency>
  49. <groupId>org.postgresql</groupId>
  50. <artifactId>postgresql</artifactId>
  51. <version>42.7.1</version>
  52. </dependency>
  53. <dependency>
  54. <groupId>com.auth0</groupId>
  55. <artifactId>java-jwt</artifactId>
  56. <version>3.16.0</version>
  57. </dependency>
  58. <dependency>
  59. <groupId>org.projectlombok</groupId>
  60. <artifactId>lombok</artifactId>
  61. <version>1.18.24</version>
  62. <scope>provided</scope>
  63. </dependency>
  64. <dependency>
  65. <groupId>org.springframework.boot</groupId>
  66. <artifactId>spring-boot-starter-test</artifactId>
  67. <scope>test</scope>
  68. </dependency>
  69. <dependency>
  70. <groupId>org.springframework.boot</groupId>
  71. <artifactId>spring-boot-starter</artifactId>
  72. </dependency>
  73. <dependency>
  74. <groupId>org.springframework.boot</groupId>
  75. <artifactId>spring-boot-starter-actuator</artifactId>
  76. </dependency>
  77. <!--
  78. https://mvnrepository.com/artifact/com.github.wendykierp/JTransforms -->
  79. <dependency>
  80. <groupId>com.github.wendykierp</groupId>
  81. <artifactId>JTransforms</artifactId>
  82. <version>3.0</version>
  83. </dependency>
  84. </dependencies>
  85. <build>
  86. <plugins>
  87. <plugin>
  88. <groupId>org.springframework.boot</groupId>
  89. <artifactId>spring-boot-maven-plugin</artifactId>
  90. </plugin>
  91. </plugins>
  92. </build>
  93. </project>


我的数据库PostgreSQL:

  1. CREATE TYPE public.maintenance AS ENUM (
  2. 'Predictive', 'Preventive', 'ScheduledCorrective', 'Corrective'
  3. );
  4. CREATE TYPE public.assetstate AS ENUM (
  5. 'WORKING', 'IDLE'
  6. );
  7. CREATE TYPE public.downtimetype AS ENUM (
  8. 'Manual', 'Automatic'
  9. );
  10. CREATE TYPE public.priority AS ENUM (
  11. 'Urgente', 'Alta', 'Media', 'Baixa'
  12. );
  13. CREATE TYPE public.servicetype AS ENUM (
  14. 'Outsourced',
  15. 'Own'
  16. );
  17. CREATE TYPE public.state AS ENUM (
  18. 'COMPLETED', 'PLANNING', 'PROGRESS', 'OPENING'
  19. );
  20. CREATE TYPE public.eventtype AS ENUM (
  21. 'ASSET_DOWN', 'ASSET_UP', 'TEMP_AN', 'VIB_AN'
  22. );
  23. CREATE TABLE client (
  24. id UUID UNIQUE PRIMARY KEY,
  25. name VARCHAR(100) NULL,
  26. email VARCHAR(100) NULL,
  27. password VARCHAR(60) NOT NULL,
  28. image_link VARCHAR(100) NULL,
  29. created_at TIMESTAMP WITHOUT TIME ZONE DEFAULT (now() AT TIME ZONE 'America/Sao_Paulo')
  30. );
  31. CREATE TABLE employee(
  32. id UUID UNIQUE PRIMARY KEY,
  33. name VARCHAR(100) NULL,
  34. email VARCHAR(100) NULL,
  35. phone VARCHAR(20) NULL,
  36. image_link VARCHAR(100) NULL,
  37. created_at TIMESTAMP WITHOUT TIME ZONE DEFAULT (now() AT TIME ZONE 'America/Sao_Paulo')
  38. );
  39. ALTER TABLE employee ADD COLUMN id_client UUID;
  40. ALTER TABLE employee ADD CONSTRAINT fk_client FOREIGN KEY (id_client)
  41. REFERENCES client (id);
  42. CREATE TABLE asset (
  43. id UUID UNIQUE PRIMARY KEY,
  44. asset_key VARCHAR(50) NULL,
  45. name VARCHAR(100) NULL,
  46. manufacturer VARCHAR(100) NULL,
  47. production_date DATE NULL,
  48. asset_location VARCHAR(100) NULL,
  49. asset_model VARCHAR(100) NULL,
  50. serial_number VARCHAR(100) NULL,
  51. maintenance_type maintenance NULL,
  52. downtime double precision NULL,
  53. downtime_type downtimetype NULL,
  54. asset_state assetstate NULL,
  55. created_at TIMESTAMP WITHOUT TIME ZONE DEFAULT (now() AT TIME ZONE 'America/Sao_Paulo')
  56. );
  57. ALTER TABLE asset ADD COLUMN id_client UUID;
  58. ALTER TABLE asset ADD CONSTRAINT fk_client FOREIGN KEY (id_client)
  59. REFERENCES client (id);
  60. CREATE TABLE data (
  61. id UUID UNIQUE PRIMARY KEY,
  62. rms_x DOUBLE PRECISION NULL,
  63. rms_y double precision NULL,
  64. rms_z DOUBLE PRECISION NULL,
  65. temperature double precision NULL,
  66. asset_key VARCHAR(50) NULL,
  67. added TIMESTAMP WITHOUT TIME ZONE DEFAULT (now() AT TIME ZONE 'America/Sao_Paulo'),
  68. is_analysed BOOLEAN DEFAULT FALSE
  69. );
  70. ALTER TABLE data ADD COLUMN id_asset UUID;
  71. ALTER TABLE data ADD CONSTRAINT fk_asset FOREIGN KEY (id_asset)
  72. REFERENCES asset (id);
  73. CREATE TABLE vibration_package (
  74. id UUID UNIQUE PRIMARY KEY,
  75. data_array double precision[] NULL,
  76. asset_key VARCHAR(50) NULL,
  77. added TIMESTAMP WITHOUT TIME ZONE DEFAULT (now() AT TIME ZONE 'America/Sao_Paulo')
  78. );
  79. ALTER TABLE vibration_package ADD COLUMN id_asset UUID;
  80. ALTER TABLE vibration_package ADD CONSTRAINT fk_asset FOREIGN KEY (id_asset)
  81. REFERENCES asset (id);
  82. CREATE TABLE workorder(
  83. id UUID UNIQUE PRIMARY KEY,
  84. name VARCHAR(100) NULL,
  85. owner VARCHAR(100) NULL,
  86. asset_key VARCHAR(100) NULL,
  87. created_date DATE NULL,
  88. conclusion_date DATE NULL,
  89. priority priority NULL,
  90. maintenance maintenance NULL,
  91. state state NULL,
  92. created_at TIMESTAMP WITHOUT TIME ZONE DEFAULT (now() AT TIME ZONE 'America/Sao_Paulo')
  93. );
  94. ALTER TABLE workorder ADD COLUMN id_client UUID;
  95. ALTER TABLE workorder ADD CONSTRAINT fk_client FOREIGN KEY (id_client)
  96. REFERENCES client (id);
  97. CREATE TABLE events(
  98. id UUID UNIQUE PRIMARY KEY,
  99. event_type eventtype NULL,
  100. description VARCHAR(100) NULL,
  101. added TIMESTAMP WITHOUT TIME ZONE
  102. );
  103. ALTER TABLE events ADD COLUMN id_asset UUID;
  104. ALTER TABLE events ADD CONSTRAINT fk_asset FOREIGN KEY (id_asset)
  105. REFERENCES asset (id);
  106. CREATE TABLE perfomaceindex(
  107. id UUID UNIQUE PRIMARY KEY,
  108. completed double precision NULL,
  109. planning double precision NULL,
  110. progress double precision NULL,
  111. opening double precision NULL,
  112. idle double precision NULL,
  113. working double precision NULL,
  114. total_downtime double precision NULL,
  115. MP double precision NULL,
  116. MPD double precision NULL,
  117. runtime_average double precision NULL,
  118. MTBF double precision NULL,
  119. MTTR double precision NULL,
  120. MTTA double precision NULL,
  121. availability double precision NULL
  122. );
  123. ALTER TABLE perfomaceindex ADD COLUMN id_client UUID;
  124. ALTER TABLE perfomaceindex ADD CONSTRAINT fk_client FOREIGN KEY (id_client)
  125. REFERENCES client (id);
  126. CREATE TABLE machineintervals(
  127. id UUID UNIQUE PRIMARY KEY,
  128. asset_state assetstate NULL,
  129. added TIMESTAMP WITHOUT TIME ZONE
  130. );
  131. ALTER TABLE machineintervals ADD COLUMN id_asset UUID;
  132. ALTER TABLE machineintervals ADD CONSTRAINT fk_asset FOREIGN KEY (id_asset)
  133. REFERENCES asset (id);


我的VibrationPackage型号:

  1. @Entity
  2. @Table(name = "vibration_package")
  3. @TypeDef(
  4. name = "list-array",
  5. typeClass = ListArrayType.class
  6. )
  7. @Getter @Setter @AllArgsConstructor @NoArgsConstructor
  8. public class VibrationPackage{
  9. @Id
  10. @GeneratedValue
  11. @Column(name = "id", columnDefinition = "uuid", nullable = false, unique = true)
  12. private UUID id;
  13. @Column(name = "asset_key", nullable = true)
  14. public String key;
  15. @Type(type = "list-array")
  16. @Column(
  17. name = "data_array",
  18. columnDefinition = "Double[]"
  19. )
  20. public List<Double> dataPackage;
  21. @Column(name = "start", nullable = true)
  22. int start;
  23. @Column(name = "end", nullable = true)
  24. int end;
  25. @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSSSS'Z'", timezone = "UTC")
  26. @Column(name = "added", nullable = false)
  27. private ZonedDateTime added = ZonedDateTime.now();
  28. @ManyToOne(fetch = FetchType.LAZY, optional = false)
  29. @OnDelete(action = OnDeleteAction.NO_ACTION)
  30. @JoinColumn(name = "id_asset", nullable = false)
  31. @JsonIgnore
  32. private Asset asset;
  33. @Override
  34. public String toString() {
  35. return "VibrationPackage [key=" + key + ", dataPackage=" + dataPackage + ", start=" + start
  36. + ", end=" + end + "]";
  37. }
  38. }

6psbrbz9

6psbrbz91#

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

相关问题