2016-02-23 28 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

相關問題