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)
我如何解決這個錯誤?
您能否在**語句中描述** mappedby =「order」** ** OneToMany(mappedBy =「order」)**? –
該字段是否映射到兩個對象中?如果是這樣,你需要像上面那樣指定mappedBy屬性。如果它唯一映射在PurchaseOrder中,則可以省略它。有關更多信息,請參閱文檔https://docs.oracle.com/javaee/6/api/javax/persistence/OneToMany.html – hyness