我想通过JPA使用具有共享主键的OneToOne注释将表连接到一个对象中,但是我不确定该怎么做。我遇到错误:
org.springframework.beans.factory.BeanCreationException:错误 在类路径中创建名称为“ entityManagerFactory”的bean 资源 [org / springframework / boot / autoconfigure / orm / jpa / HibernateJpaConfiguration.class]: 调用init方法失败;嵌套异常为 org.hibernate.AnnotationException:未知的映射于: com.maciejg.School02.model.StudentsTeachersEntity.loginAndPassword, 引用的属性未知: com.maciejg.School02.model.LoginAndPassword.usersinfo
@Entity
@Table(name="usersinfo")
public class StudentsTeachersEntity {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long id;
@Column(name = "name")
private String name;
@Column(name = "surname")
private String surname;
@Column(name = "username")
private String username;
@Column(name = "pesel")
private String pesel;
@Column(name = "phone_number")
private String phoneNumber;
@Column(name = "address")
private String address;
@Column(name = "email")
private String email;
@OneToOne(mappedBy = "usersinfo", cascade =
CascadeType.ALL)
private LoginAndPassword loginAndPassword;
//getters and setters
@Entity
@Table(name="userandpassword")
public class LoginAndPassword {
@Id
@GeneratedValue(strategy= GenerationType.IDENTITY)
private Long username_id;
@Column(name = "username")
private String username;
@Column(name = "user_password")
private String user_password;
@Column(name= "grade")
private String grade;
@Column(name= "comment")
private String comment;
@OneToOne
@JoinColumn
@MapsId
private StudentsTeachersEntity studentsTeachersEntity;
//getters and setters