我有类(class)用户:
@Entity
public class User {
@Id
@GeneratedValue
private Integer id;
private String name;
private String password;
@ManyToMany
@JoinTable
private List<Role> roles;
}
类所有者继承自用户
@Entity
public class Owner extends User {
private String pesel;
private String adress;
@OneToMany(cascade={CascadeType.PERSIST, CascadeType.REMOVE})
private List<Pet> pets;
}
并且主人有宠物
public class Pet {
@Id
@GeneratedValue
private Integer id;
private String name;
private String weight;
@ManyToOne
private Owner owner;
}
为什么启动应用程序时出现错误:
org.springframework.data.mapping.PropertyReferenceException: No property user found for type Pet!
现在我尝试将 User 实例分享给医生和动物的主人
问题是我不知道我是否正在做映射,因此想问它是否必须看起来像
--编辑2
我稍微简化了该方案,以更好地说明发生的情况
--编辑3
目前我的对象已呈现:
@Entity
public class Pet {
@Id
@GeneratedValue
private Integer id;
private String name;
private String weight;
}
用户
@Entity
public class User {
@Id
@GeneratedValue
private Integer id;
private String name;
private String password;
@ManyToMany
@JoinTable(name="user_roles")
private List<Role> roles;
}
宠物主人
@Entity
public class PetOwner extends User {
private String pesel;
private String adress;
@OneToMany(mappedBy="petOwner")
private List<Pet> pets;
}
最佳答案
我替换
@ManyToOne
private PetOwner petOwner;
对于
@ManyToOne
private Owner petOwner;
并且它有效。你有 PetOwner 类(class)吗?
还提供日志错误以获取有关它的更多信息
关于java - Spring JPA 映射 - 第一步,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35394002/