我正在嘗試執行“spring-boot:run”并希望為所有五個變數生成列:
@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
我是否需要在物體類和產品類之間使用映射。需要對此提出建議嗎?
uj5u.com熱心網友回復:
你的評論:
**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 的列,但是您可能想要做的是有一個連接表。
該錯誤告訴您您的映射不被理解,您的用例應該使用多對多關系,并且您需要一個單獨的表來保存外鍵。基本上使用@ManyToMany注釋產品和變體屬性并指定連接表,這留給您作為練習。以
https://www.baeldung.com/jpa-many-to-many為例
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/473491.html
