0
votes

I have this error when I compile. In test I don't have problem.

I have the dependency javax.xml.bind, jaxb-api.

Error:

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

Entities:

@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;
1
I doubt that this is during compilation.. Rather an integration test or starting your application. - M. Deinum

1 Answers

1
votes

The problem is that you have a many to many relationship which was mapped in your case as a many to one and one to many.

You have a many to many relationship between Accessory and Lang. JPA lets you better map it directly.

Please check this article or search for "JPA many to many mapping" https://vladmihalcea.com/the-best-way-to-use-the-manytomany-annotation-with-jpa-and-hibernate/