编译时出现此错误。在测试中我没问题。
我有javax.xml.bind
,jaxb-api
的依存关系。
错误:
原因:org.springframework.beans.factory.BeanCreationException: 创建类中定义的名称为'entityManagerFactory'的bean时出错 路径资源 [org / springframework / boot / autoconfigure / orm / jpa / HibernateJpaConfiguration.class]: 调用init方法失败;嵌套异常为 org.hibernate.AnnotationException:mappedBy引用未知 目标实体属性: com.endoorment.models.entity.AccessoryLang.accessory在 com.endoorment.models.entity.Accessory.accessorylang
实体:
@Entity
@Table(name = "accessories")
public class Accessory implements Serializable {
private static final long serialVersionUID = 1L;
@Id
private Integer id;
@OneToMany(mappedBy = "accessory", cascade = CascadeType.ALL)
private Set<AccessoryLang> accessorylang = new HashSet<AccessoryLang>();
@Entity
@Table(name = "accessories_langs")
public class AccessoryLang implements Serializable {
private static final long serialVersionUID = 1L;
@EmbeddedId
private AccessoryLangId accessorylangid;
@ManyToOne(fetch = FetchType.LAZY)
@MapsId("accessoryId")
@JoinColumn(name = "accessories_id", nullable = false)
@OnDelete(action = OnDeleteAction.CASCADE)
@JsonIgnore
private Accessory accessory;
@ManyToOne(fetch = FetchType.LAZY)
@MapsId("langId")
@JoinColumn(name = "langs_id", nullable = false)
@OnDelete(action = OnDeleteAction.CASCADE)
@JsonIgnore
private Lang lang;
@Column(nullable = false, length = 45)
@NotEmpty
private String name;
答案 0 :(得分:0)
问题是您有多对多关系,这种情况在您的案例中被映射为多对一和一对多。
您在配件和Lang之间有多对多的关系。 JPA使您可以更好地直接映射它。
请检查本文或搜索“ JPA多对多映射” https://vladmihalcea.com/the-best-way-to-use-the-manytomany-annotation-with-jpa-and-hibernate/