java org.hibernate.MappingException:无法确定类型:在表:列:[org.hibernate.mapping.Column(植物)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35581630/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
org.hibernate.MappingException: Could not determine type for: at table: for columns: [org.hibernate.mapping.Column(plant)
提问by Jeff
I know this question have been asked several timesbut, they didn't help me. I have the following test:
我知道这个问题已经被问过好几次了,但他们没有帮助我。我有以下测试:
public class PlantCatalogTests {
@Autowired
PlantInventoryEntryRepository plantRepo;
@Test
public void queryPlantCatalog() {
assertThat(plantRepo.count(), is(14l));
}
and here is PlantInventoryEntryRepository
这是PlantInventoryEntryRepository
@Repository
public interface PlantInventoryEntryRepository extends JpaRepository<PlantInventoryEntry, Long> {}
As you see, this repository is based on the class PlantInventoryEntry
如您所见,此存储库基于类PlantInventoryEntry
@Entity
@Data
public class PlantInventoryEntry {
@Id
@GeneratedValue
Long id;
@OneToOne
PurchaseOrder plant_id;
String name;
String description;
String price;
}
PurchaseOrder is another class, which i have one instance of it as an attribute in my PlantInventoryEntryclass:
PurchaseOrder 是另一个类,我有一个实例作为我的PlantInventoryEntry类中的一个属性:
@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;
}
My main problem is that, when i run my test, i face with this error:
我的主要问题是,当我运行测试时,我遇到了这个错误:
org.hibernate.MappingException: Could not determine type for: com.example.models.PlantInventoryEntry, at table: purchase_order, for columns: [org.hibernate.mapping.Column(plant)
How can i fix the error??
我该如何修复错误?
回答by hyness
You need to identify the relationship by using a @ManyToOneor @OneToOneannotation on PlantInventoryEntryin PurchaseOrder, depending on what the actual relationship is between the entities.
你需要通过使用来识别关系@ManyToOne或者@OneToOne上标注PlantInventoryEntry中的PurchaseOrder,根据实际关系是实体之间是什么。
Edit:You most likely need to identify the relatationship between the List of PlantReservations and PurchaseOrder, or you need to mark it as @Transientif its not managed by JPA.
编辑:您很可能需要确定 List of PlantReservation和PurchaseOrder之间的关系,或者如果它不受 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;
}