org.hibernate.MappingException: Could not determine type for: at table: for columns: [org.hibernate.mapping.Column(plant)
我知道这个问题已经问了好几次了,但他们没有帮我。我有以下测试:
1 2 3 4 5 6 7 8 | public class PlantCatalogTests { @Autowired PlantInventoryEntryRepository plantRepo; @Test public void queryPlantCatalog() { assertThat(plantRepo.count(), is(14l)); } |
这是工厂库存报告
1 2 | @Repository public interface PlantInventoryEntryRepository extends JpaRepository<PlantInventoryEntry, Long> {} |
号
如您所见,此存储库基于plantInventoryEntry类
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
PurchaseOrder是另一个类,我在PlantInventoryEntry类中将它的一个实例作为属性:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | @Entity @Data public class PurchaseOrder { @Id @GeneratedValue Long id; List<PlantReservation> reservations; PlantInventoryEntry plant; LocalDate issueDate; LocalDate paymentSchedule; @Column(precision=8,scale=2) BigDecimal total; @Enumerated(EnumType.STRING) POStatus status; LocalDate startDate; LocalDate endDate; } |
。
我的主要问题是,当我运行测试时,我会遇到以下错误:
1 | org.hibernate.MappingException: Could not determine type for: com.example.models.PlantInventoryEntry, at table: purchase_order, for columns: [org.hibernate.mapping.Column(plant) |
如何修复错误??
根据实体之间的实际关系,您需要使用purchaseorder中plantInventoryEntry上的@manytoone或@onetoone注释来标识关系。
编辑:您很可能需要确定植物保留列表和采购订单之间的关系,或者如果不由JPA管理,您需要将其标记为@transient。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | @Entity @Data public class PurchaseOrder { @Id @GeneratedValue Long id; // You need to set the mappedBy attribute to the field name // of PurchaseOrder in PlantReservation // Update: omit mappedBy if PurchaseOrder is not mapped in PlantReservation @OneToMany(mappedBy="order") List<PlantReservation> reservations; @ManyToOne PlantInventoryEntry plant; LocalDate issueDate; LocalDate paymentSchedule; @Column(precision=8,scale=2) BigDecimal total; @Enumerated(EnumType.STRING) POStatus status; LocalDate startDate; LocalDate endDate; } |