org.hibernate.MappingException: Could not determine type for: at table: for columns: [org.hibernate.mapping.Column(plant)

旧时模样 提交于 2021-01-28 20:03:25

问题


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

and here is PlantInventoryEntryRepository

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

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 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)

How can i fix the error??


回答1:


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.

Edit: 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;
    }


来源:https://stackoverflow.com/questions/35581630/org-hibernate-mappingexception-could-not-determine-type-for-at-table-for-colu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!