Spring 启动错误创建名称为 'entityManagerFactory' 的 bean 在 class 路径资源中定义
Spring boot Error creating bean with name 'entityManagerFactory' defined in class path resource
我正在尝试执行“spring-boot:运行”并希望为所有
五个变量:
@Entity
Class Shopping{
@Id
@GeneratedValue
private int id;
private ShopifyInfo shop_info;
private int product_count;
private List<Products> products;
private List<Variants> variants;
}
但是我收到这个错误:
022-05-11 21:46:20.710 ERROR 25420 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Failed to initialize JPA EntityManagerFactory: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.MappingException: Could not determine type for: java.util.List, at table: shopify, for columns: [org.hibernate.mapping.Column(products)]
2022-05-11 21:46:20.710 WARN 25420 --- [ restartedMain] 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]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.MappingException: Could not determine type for: java.util.List, at table: shopify, for columns: [org.hibernate.mapping.Column(products)]
2022-05-11 21:46:20.710 INFO 25420 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
2022-05-11 21:46:20.793 INFO 25420 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
2022-05-11 21:46:20.796 INFO 25420 --- [ restartedMain] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2022-05-11 21:46:20.812 INFO 25420 --- [ restartedMain] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-05-11 21:46:20.945 ERROR 25420 --- [ restartedMain] o.s.boot.SpringApplication : Application run failed
我需要使用实体 class 和产品 class 之间的映射吗?需要对此提出建议吗?
您的评论:
**Here I'm trying to do a "spring-boot:run" and want to generate columns for all above
five variables. But I'm getting this error :**
表示您希望在购物中包含包含产品 ID 和变体的列 table,但是您可能想要做的是加入一个 table.
错误告诉你你的映射不被理解,你的用例应该使用多对多关系,你需要一个单独的 table 来保存外键。基本上用 @ManyToMany 注释 products 和 variants 属性并指定连接 table,这是留给你的练习。
检查 https://www.baeldung.com/jpa-many-to-many 示例
我正在尝试执行“spring-boot:运行”并希望为所有 五个变量:
@Entity
Class Shopping{
@Id
@GeneratedValue
private int id;
private ShopifyInfo shop_info;
private int product_count;
private List<Products> products;
private List<Variants> variants;
}
但是我收到这个错误:
022-05-11 21:46:20.710 ERROR 25420 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Failed to initialize JPA EntityManagerFactory: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.MappingException: Could not determine type for: java.util.List, at table: shopify, for columns: [org.hibernate.mapping.Column(products)]
2022-05-11 21:46:20.710 WARN 25420 --- [ restartedMain] 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]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.MappingException: Could not determine type for: java.util.List, at table: shopify, for columns: [org.hibernate.mapping.Column(products)]
2022-05-11 21:46:20.710 INFO 25420 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
2022-05-11 21:46:20.793 INFO 25420 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
2022-05-11 21:46:20.796 INFO 25420 --- [ restartedMain] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2022-05-11 21:46:20.812 INFO 25420 --- [ restartedMain] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-05-11 21:46:20.945 ERROR 25420 --- [ restartedMain] o.s.boot.SpringApplication : Application run failed
我需要使用实体 class 和产品 class 之间的映射吗?需要对此提出建议吗?
您的评论:
**Here I'm trying to do a "spring-boot:run" and want to generate columns for all above
five variables. But I'm getting this error :**
表示您希望在购物中包含包含产品 ID 和变体的列 table,但是您可能想要做的是加入一个 table.
错误告诉你你的映射不被理解,你的用例应该使用多对多关系,你需要一个单独的 table 来保存外键。基本上用 @ManyToMany 注释 products 和 variants 属性并指定连接 table,这是留给你的练习。
检查 https://www.baeldung.com/jpa-many-to-many 示例