gpt4 book ai didi

java - 引用的属性不是 (One|Many)ToOne : in mappedBy of

转载 作者:行者123 更新时间:2023-12-01 16:28:22 25 4
gpt4 key购买 nike

我对 hibernate 还很陌生。我必须分类:相关的用户(父)和区域(子),用户与区域具有 FK。我正在处理 hibernate 关系,但出现错误:

2020-05-31 12:39:53.442  WARN  --- [  restartedMain] ationConfigEmbeddedWebApplicationContext : Exception encountered

during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: Referenced property not a (One|Many)ToOne: com.telefonica.npro.model.Area.id_area in mappedBy of com.telefonica.npro.model.User.area

这是用户:

    @Entity
@Table(name = "NPRO_USUARIOS")
public class User implements Serializable {

private static final long serialVersionUID = -1330075515340995797L;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@NotNull
@Column
private int id_usuario;

@Column
@NotNull
private String nombre_usuario;


@OneToOne(mappedBy = "id_sociedad", cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.DETACH, CascadeType.REFRESH })
private Sociedad sociedad;


@OneToOne(mappedBy = "id_area", cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.DETACH, CascadeType.REFRESH })
private Area area;

@Column
@NotNull
private String matricula_usuario;


@Column
@NotNull
private String email_usuario;

@ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.DETACH, CascadeType.REFRESH })
@JoinColumn(name="id_perfil")
private Perfil perfil;

}

这是区域:

@Entity
@Table(name = "NPRO_MAESTRO_AREAS")
public class Area implements Serializable {

private static final long serialVersionUID = -1330075515340995797L;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@NotNull
@Column
private int id_area;

@NotNull
@Column
private String nombre_area;

@Column
private LocalDateTime fecha_modif;
@Column
private String observaciones;
@Column
private int usuario_modif;
@Column
@NotNull
private String activo;

@ManyToOne
@JoinColumn(name="id_sociedad")
private Sociedad sociedad;

@OneToOne
@JoinColumn(name="id_usuario")
private User user;
}

我不知道出了什么问题..提前致谢!

安东尼奥

最佳答案

mappedBy 应该是相关实体中可以导航回当前实体的字段。因此对于 User ,它应该是 Area 中的 user 字段:

@Entity
@Table(name = "NPRO_USUARIOS")
public class User implements Serializable {


@OneToOne(mappedBy = "user", cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.DETACH, CascadeType.REFRESH })
private Area area;
}

关于java - 引用的属性不是 (One|Many)ToOne : in mappedBy of,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62115062/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com