org.hibernate.MappingException:无法确定以下类型:表:对于列:[org.hibernate.mapping.Column(plant) [英] org.hibernate.MappingException: Could not determine type for: at table: for columns: [org.hibernate.mapping.Column(plant)

查看:79
本文介绍了org.hibernate.MappingException:无法确定以下类型:表:对于列:[org.hibernate.mapping.Column(plant)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有人问过这个问题

I know this question have been asked several times but, 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)); 
    }

这是 PlantInventoryEntryRepository

@Repository
public interface PlantInventoryEntryRepository  extends JpaRepository<PlantInventoryEntry, Long> {}

如您所见,该存储库基于类 PlantInventoryEntry

As you see, this repository is based on the class PlantInventoryEntry

@Entity
@Data
public class PlantInventoryEntry {

      @Id
      @GeneratedValue
      Long id;

      @OneToOne
      PurchaseOrder plant_id;

      String name;
      String description;

      String price;   
}

PurchaseOrder是另一个类,在我的 PlantInventoryEntry 类中,我有一个实例作为属性:

PurchaseOrder is another class, which i have one instance of it as an attribute in my 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;
    }

我的主要问题是,当我运行测试时,我会遇到此错误:

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)

我该如何解决错误?

推荐答案

您需要使用上的 @ManyToOne @OneToOne 注释来识别关系. PurchaseOrder 中的PlantInventoryEntry ,具体取决于实体之间的实际关系.

You need to identify the relationship by using a @ManyToOne or @OneToOne annotation on PlantInventoryEntry in PurchaseOrder, depending on what the actual relationship is between the entities.

编辑:您最有可能需要确定 PlantReservation 列表与 PurchaseOrder 之间的关系,或者将其标记为 @Transient (如果不受JPA管理).

You most likely need to identify the relatationship between the List of PlantReservations and PurchaseOrder, or you need to mark it as @Transient if its not managed by JPA.

@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;
    }

这篇关于org.hibernate.MappingException:无法确定以下类型:表:对于列:[org.hibernate.mapping.Column(plant)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆