gpt4 book ai didi

java - 编译: Error creating bean with name 'entityManagerFactory'

转载 作者:行者123 更新时间:2023-12-02 10:15:47 25 4
gpt4 key购买 nike

编译的时候出现这个错误。在测试中我没有问题。

我有依赖项javax.xml.bindjaxb-api

错误:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: com.endoorment.models.entity.AccessoryLang.accessory in 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;

最佳答案

问题是您有一个多对多关系,在您的案例中映射为多对一和一对多。

Accessory 和 Lang 之间存在多对多关系。 JPA 让您可以更好地直接映射它。

请查看这篇文章或搜索“JPA 多对多映射” https://vladmihalcea.com/the-best-way-to-use-the-manytomany-annotation-with-jpa-and-hibernate/

关于java - 编译: Error creating bean with name 'entityManagerFactory' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54697463/

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