我一直在搜索,可能我找到的最接近的东西是这个Stack Overflow thread,但它仍然没有回答我的问题。即使使用最新的spring(截至本文撰写)框架(2.7.2)、hibernate
(6.1.2.Final)和hibernate-entitymanager
(5.6.10.Final),我仍然遇到麻烦。我的完整错误堆栈如下所示:
INFO <PID> --- [main] com.lms.controller.SpringBootController : Starting SpringBootController using Java 17.0.4 on <OS> with PID <PID> <FILEPATH> started by <USER> in <FILEPATH>)
INFO <PID> --- [main] com.lms.controller.SpringBootController : No active profile set, falling back to 1 default profile: "default"
INFO <PID> --- [main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
INFO <PID> --- [main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 28 ms. Found 2 JPA repository interfaces.
INFO <PID> --- [main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
INFO <PID> --- [main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
INFO <PID> --- [main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/10.0.22]
INFO <PID> --- [main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
INFO <PID> --- [main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 944 ms
INFO <PID> --- [main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
INFO <PID> --- [main] org.hibernate.Version : HHH000412: Hibernate ORM core version 6.1.2.Final
WARN <PID> --- [main] org.hibernate.orm.deprecation : HHH90000021: Encountered deprecated setting [javax.persistence.sharedCache.mode], use [jakarta.persistence.sharedCache.mode] instead
INFO <PID> --- [main] SQL dialect : HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect
ERROR <PID> --- [main] j.LocalContainerEntityManagerFactoryBean : Failed to initialize JPA EntityManagerFactory: Could not determine recommended JdbcType for `com.lms.entity.Role`
WARN <PID> --- [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]: Could not determine recommended JdbcType for `com.lms.entity.Role`
INFO <PID> --- [main] com.lms.controller.SpringBootController : Starting SpringBootController using Java 17.0.4 on <OS> with PID <PID> <FILEPATH> started by <USER> in <FILEPATH>)
INFO <PID> --- [main] com.lms.controller.SpringBootController : No active profile set, falling back to 1 default profile: "default"
INFO <PID> --- [main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
INFO <PID> --- [main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 28 ms. Found 2 JPA repository interfaces.
INFO <PID> --- [main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
INFO <PID> --- [main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
INFO <PID> --- [main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/10.0.22]
INFO <PID> --- [main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
INFO <PID> --- [main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 944 ms
INFO <PID> --- [main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
INFO <PID> --- [main] org.hibernate.Version : HHH000412: Hibernate ORM core version 6.1.2.Final
WARN <PID> --- [main] org.hibernate.orm.deprecation : HHH90000021: Encountered deprecated setting [javax.persistence.sharedCache.mode], use [jakarta.persistence.sharedCache.mode] instead
INFO <PID> --- [main] SQL dialect : HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect
ERROR <PID> --- [main] j.LocalContainerEntityManagerFactoryBean : Failed to initialize JPA EntityManagerFactory: Could not determine recommended JdbcType for `com.lms.entity.Role`
WARN <PID> --- [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]: Could not determine recommended JdbcType for `com.lms.entity.Role`
INFO <PID> --- [main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
INFO <PID> --- [main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
ERROR <PID> --- [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]: Could not determine recommended JdbcType for `com.lms.entity.Role`
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1753) ~[spring-beans-6.0.0-M5.jar:6.0.0-M5]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:604) ~[spring-beans-6.0.0-M5.jar:6.0.0-M5]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:526) ~[spring-beans-6.0.0-M5.jar:6.0.0-M5]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:326) ~[spring-beans-6.0.0-M5.jar:6.0.0-M5]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-6.0.0-M5.jar:6.0.0-M5]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:324) ~[spring-beans-6.0.0-M5.jar:6.0.0-M5]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) ~[spring-beans-6.0.0-M5.jar:6.0.0-M5]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1141) ~[spring-context-6.0.0-M5.jar:6.0.0-M5]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:916) ~[spring-context-6.0.0-M5.jar:6.0.0-M5]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:592) ~[spring-context-6.0.0-M5.jar:6.0.0-M5]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146) ~[spring-boot-3.0.0-M4.jar:3.0.0-M4]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:731) ~[spring-boot-3.0.0-M4.jar:3.0.0-M4]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:430) ~[spring-boot-3.0.0-M4.jar:3.0.0-M4]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:312) ~[spring-boot-3.0.0-M4.jar:3.0.0-M4]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1303) ~[spring-boot-3.0.0-M4.jar:3.0.0-M4]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1292) ~[spring-boot-3.0.0-M4.jar:3.0.0-M4]
at com.lms.controller.SpringBootController.main(SpringBootController.java:30) ~[classes/:na]
Caused by: org.hibernate.type.descriptor.java.spi.JdbcTypeRecommendationException: Could not determine recommended JdbcType for `com.lms.entity.Role`
at org.hibernate.type.descriptor.java.spi.UnknownBasicJavaType.getRecommendedJdbcType(UnknownBasicJavaType.java:37) ~[hibernate-core-6.1.2.Final.jar:6.1.2.Final]
at org.hibernate.type.descriptor.java.spi.BasicCollectionJavaType.getRecommendedJdbcType(BasicCollectionJavaType.java:70) ~[hibernate-core-6.1.2.Final.jar:6.1.2.Final]
at org.hibernate.boot.model.process.internal.InferredBasicValueResolver.from(InferredBasicValueResolver.java:222) ~[hibernate-core-6.1.2.Final.jar:6.1.2.Final]
at org.hibernate.mapping.BasicValue.buildResolution(BasicValue.java:507) ~[hibernate-core-6.1.2.Final.jar:6.1.2.Final]
at org.hibernate.mapping.BasicValue.resolve(BasicValue.java:315) ~[hibernate-core-6.1.2.Final.jar:6.1.2.Final]
at org.hibernate.mapping.BasicValue.resolve(BasicValue.java:305) ~[hibernate-core-6.1.2.Final.jar:6.1.2.Final]
at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.lambda$processValueResolvers$4(InFlightMetadataCollectorImpl.java:1766) ~[hibernate-core-6.1.2.Final.jar:6.1.2.Final]
at java.base/java.util.ArrayList.removeIf(ArrayList.java:1682) ~[na:na]
at java.base/java.util.ArrayList.removeIf(ArrayList.java:1660) ~[na:na]
at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processValueResolvers(InFlightMetadataCollectorImpl.java:1765) ~[hibernate-core-6.1.2.Final.jar:6.1.2.Final]
at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1751) ~[hibernate-core-6.1.2.Final.jar:6.1.2.Final]
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:300) ~[hibernate-core-6.1.2.Final.jar:6.1.2.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:1350) ~[hibernate-core-6.1.2.Final.jar:6.1.2.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1421) ~[hibernate-core-6.1.2.Final.jar:6.1.2.Final]
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:57) ~[spring-orm-6.0.0-M5.jar:6.0.0-M5]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:362) ~[spring-orm-6.0.0-M5.jar:6.0.0-M5]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:409) ~[spring-orm-6.0.0-M5.jar:6.0.0-M5]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:396) ~[spring-orm-6.0.0-M5.jar:6.0.0-M5]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:338) ~[spring-orm-6.0.0-M5.jar:6.0.0-M5]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1799) ~[spring-beans-6.0.0-M5.jar:6.0.0-M5]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1749) ~[spring-beans-6.0.0-M5.jar:6.0.0-M5]
... 16 common frames omitted
下面是我的Role.java
文件:
package com.lms.entity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import jakarta.persistence.EnumType;
@Entity
@Table(name = "roles")
public class Role {
@Id
@Column(name = "roleID", nullable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int roleID;
@Enumerated(EnumType.STRING)
@Column(name = "roleName", nullable = false)
private RoleEnum roleName;
public int getRoleID(){
return this.roleID;
}
public void setRoleID(int roleid){
this.roleID = roleid;
}
public RoleEnum getRoleName(){
return this.roleName;
}
public void setRoleName(RoleEnum rolename){
this.roleName = rolename;
}
@Override
public String toString(){
return "The role's id is: " + this.roleID + "\nThe role's name is: " + this.roleName.toString();
}
}
即使我的Role.java
只包含roleID值,我也会得到相同的错误,这在我的其他实体类上是没有的,这些实体类基本上是相同的。这个类唯一的独特之处是RoleEnum
类型,它基于这个枚举类:RoleEnum.java
public enum RoleEnum {
SUPER_ADMIN,
FORUM_ADMIN,
ACCOUNTANT,
LIBRARIAN,
NORMAL_USER,
FORUM_USER
}
当我试图在Java Spring和Works中复制实现JWT的this person's guide时,我遇到了这个错误,但是他们使用的是2.2.11.RELEASE
,而不是我正在使用的3.0.0-M4
。
我认为可能的候选项是jakarta.*
而不是javax.*
有一些奇怪的地方,我不完全理解它们之间的区别。我认为可能有问题的另一个候选项是EntityManager的一些地方导致了问题,但我找不到任何关于它的信息。我的错误是Could not determine recommended JdbcType for com.lms.entity.Role
,我可以做些什么来修复这个问题吗?
1条答案
按热度按时间biswetbf1#
我有一个类似的错误。不是真正的依赖问题。
在我的例子中,我发现Payment实体与其他实体有关系,并且实际上在其他地方使用。
通过删除在其他实体中使用的实体的此示例修复了该错误,因此不会“混淆”Hibernate如何创建付款实体。