[英]Spring JPA mapping - first steps
I have class User: 我有班级用户:
@Entity
public class User {
@Id
@GeneratedValue
private Integer id;
private String name;
private String password;
@ManyToMany
@JoinTable
private List<Role> roles;
}
Class Owner inherits from User 类所有者从用户继承
@Entity
public class Owner extends User {
private String pesel;
private String adress;
@OneToMany(cascade={CascadeType.PERSIST, CascadeType.REMOVE})
private List<Pet> pets;
}
and Owner had Pet 和主人养了宠物
public class Pet {
@Id
@GeneratedValue
private Integer id;
private String name;
private String weight;
@ManyToOne
private Owner owner;
}
Why when starting the application gets the error: 为什么在启动应用程序时出现错误:
org.springframework.data.mapping.PropertyReferenceException: No property user found for type Pet!
org.springframework.data.mapping.PropertyReferenceException:没有找到类型为Pet的属性用户!
--EDIT First I have version, which was as follows: --EDIT首先,我有一个版本,如下所示:
now I try to share User instance to a doctor and the owner of the animal 现在我尝试将用户实例共享给医生和动物的所有者
The problem is that I do not know whether I am doing the mapping , and therefore wanted to ask whether it must look like 问题是我不知道我是否正在做映射,因此想问一下它是否必须看起来像
--edit2 --edit2
I've simplified the scheme just a bit to better illustrate what happens 我将方案简化了一点,以更好地说明发生了什么
--edit3 --edit3
Currently my Object's was presented: 目前,我的对象是:
@Entity
public class Pet {
@Id
@GeneratedValue
private Integer id;
private String name;
private String weight;
}
User 用户
@Entity
public class User {
@Id
@GeneratedValue
private Integer id;
private String name;
private String password;
@ManyToMany
@JoinTable(name="user_roles")
private List<Role> roles;
}
PetOwner PetOwner
@Entity
public class PetOwner extends User {
private String pesel;
private String adress;
@OneToMany(mappedBy="petOwner")
private List<Pet> pets;
}
I replace 我取代
@ManyToOne
private PetOwner petOwner;
for 对于
@ManyToOne
private Owner petOwner;
and it works. 而且有效。 Do you have a PetOwner class?
您有PetOwner类吗?
Also provide the log error to get more information about it 还提供日志错误以获取有关此错误的更多信息
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.