2016-02-23 32 views
0

我知道这个问题已被问到several times但他们没有帮助我。 我有以下测试:org.hibernate.MappingException:无法确定类型:在表格中:for列:[org.hibernate.mapping.Column(plant)

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

@Entity 
@Data 
public class PlantInventoryEntry { 

     @Id 
     @GeneratedValue 
     Long id; 

     @OneToOne 
     PurchaseOrder plant_id; 

     String name; 
     String description; 

     String price; 
} 

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

我的主要问题是,当我运行我的测试,我面对这个错误:

org.hibernate.MappingException: Could not determine type for: com.example.models.PlantInventoryEntry, at table: purchase_order, for columns: [org.hibernate.mapping.Column(plant) 

我如何解决这个错误?

回答

0

您需要使用一个@ManyToOne@OneToOne注释上PlantInventoryEntry识别的关系,的PurchaseOrder,根据实际关系是实体之间是什么。

编辑:你最有可能需要确定的PlantReservation是清单和的PurchaseOrder之间的relatationship,或者你需要将其标记为@Transient如果它不是由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; 
    } 
+0

您能否在**语句中描述** mappedby =“order”** ** OneToMany(mappedBy =“order”)**? –

+0

该字段是否映射到两个对象中?如果是这样,你需要像上面那样指定mappedBy属性。如果它唯一映射在PurchaseOrder中,则可以省略它。有关更多信息,请参阅文档https://docs.oracle.com/javaee/6/api/javax/persistence/OneToMany.html – hyness

相关问题