org.hibernate.MappingException:无法确定类型:在 table:对于列:[org.hibernate.mapping.Column(植物)
org.hibernate.MappingException: Could not determine type for: at table: for columns: [org.hibernate.mapping.Column(plant)
我知道有人问过这个问题 several times 但是,他们没有帮助我。
我有以下测试:
public class PlantCatalogTests {
@Autowired
PlantInventoryEntryRepository plantRepo;
@Test
public void queryPlantCatalog() {
assertThat(plantRepo.count(), is(14l));
}
这里是 PlantInventoryEntryRepository
@Repository
public interface PlantInventoryEntryRepository extends JpaRepository<PlantInventoryEntry, Long> {}
如您所见,此存储库基于 class PlantInventoryEntry
@Entity
@Data
public class PlantInventoryEntry {
@Id
@GeneratedValue
Long id;
@OneToOne
PurchaseOrder plant_id;
String name;
String description;
String price;
}
PurchaseOrder 是另一个 class,我在 PlantInventoryEntry class:
中有一个它的实例作为属性
@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;
}
我的主要问题是,当我 运行 我的测试时,我遇到了这个错误:
org.hibernate.MappingException: Could not determine type for: com.example.models.PlantInventoryEntry, at table: purchase_order, for columns: [org.hibernate.mapping.Column(plant)
我该如何修复错误?
您需要在 PlantInventoryEntry[=25] 上使用 @ManyToOne 或 @OneToOne 注释来识别关系=] 在 PurchaseOrder 中,取决于实体之间的实际关系。
编辑: 您很可能需要确定 PlantReservation 列表与 PurchaseOrder[= 之间的关系25=],或者如果它不是由 JPA 管理的,则需要将其标记为 @Transient。
@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;
}
我知道有人问过这个问题 several times 但是,他们没有帮助我。 我有以下测试:
public class PlantCatalogTests {
@Autowired
PlantInventoryEntryRepository plantRepo;
@Test
public void queryPlantCatalog() {
assertThat(plantRepo.count(), is(14l));
}
这里是 PlantInventoryEntryRepository
@Repository
public interface PlantInventoryEntryRepository extends JpaRepository<PlantInventoryEntry, Long> {}
如您所见,此存储库基于 class PlantInventoryEntry
@Entity
@Data
public class PlantInventoryEntry {
@Id
@GeneratedValue
Long id;
@OneToOne
PurchaseOrder plant_id;
String name;
String description;
String price;
}
PurchaseOrder 是另一个 class,我在 PlantInventoryEntry class:
中有一个它的实例作为属性@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;
}
我的主要问题是,当我 运行 我的测试时,我遇到了这个错误:
org.hibernate.MappingException: Could not determine type for: com.example.models.PlantInventoryEntry, at table: purchase_order, for columns: [org.hibernate.mapping.Column(plant)
我该如何修复错误?
您需要在 PlantInventoryEntry[=25] 上使用 @ManyToOne 或 @OneToOne 注释来识别关系=] 在 PurchaseOrder 中,取决于实体之间的实际关系。
编辑: 您很可能需要确定 PlantReservation 列表与 PurchaseOrder[= 之间的关系25=],或者如果它不是由 JPA 管理的,则需要将其标记为 @Transient。
@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;
}