即使我認爲一切都看起來確定,但我得到了一個奇怪的錯誤。JpaRepository接口 - 沒有財產所有者發現
寵物類:
@Entity
public class Pet {
@Id
@GeneratedValue
private long id;
....
@ManyToOne(cascade = CascadeType.PERSIST)
@JoinColumn(name = "owner_id")
private PetOwner petOwner;
}
PetOwner
@Entity(name = "pet_owner")
public class PetOwner extends User{
...
@OneToMany(cascade = CascadeType.ALL,mappedBy = "petOwner")
private List<Pet> pets;
}
寵物庫
@Repository
public interface PetRepository extends JpaRepository<Pet, Long> {
List<Pet> findByOwner(PetOwner owner);
}
正如你可以看到我想要得到的動物給業主的名單。在應用程序運行期間得到錯誤:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'petRepository': Invocation of init method failed; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property owner found for type Pet!
爲什麼會出現此錯誤?
好的。它正在工作。你現在可以解釋爲什麼嗎? 我以爲這是方法的名稱,並不取決於豆的名字 – Adamo
謝謝。我明白 – Adamo