Hibernate错误:mappedBy引用未知的目标实体属性

时间:2017-11-26 11:28:40

标签: jpa spring-boot hibernate-mapping

我在设置实体中的多对多关系时遇到问题。我不明白为什么

href='javascript:reportUser("azZkVUpgbG");'

我的实体:

failed; nested exception is org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: cardgame.bean.User.card in cardgame.bean.Card.users

我的用户emtity:

@MappedSuperclass
@Data
public class BaseEntity implements Serializable {

@Id
@Column(name = "id", nullable = false, unique = true)
private String id;

public BaseEntity() {
    this.id = UUID.randomUUID().toString();
}
}

我的卡片实体:

@Data
@Entity
@Table(name = "users")
public class User extends BaseEntity {

@Column(name = "username", nullable = false, unique = true)
private String username;

@Column(name = "uuid", nullable = false)
private String uuid;

@Column(name = "email", nullable = false, unique = true)
private String email;

@OneToMany(mappedBy = "user", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
private List<Card> cards;

@Column(name = "isActive", nullable = false)
private boolean isActive;
}

用户和卡表通过user_card表具有多对多关系:

@Data
@Entity
@Table(name = "cards")
public class Card extends BaseEntity {

@OneToMany(mappedBy = "card")
private List<User> users;

@Column(name = "strength", nullable = false)
private int strength;

@Column(name = "isActive", nullable = false)
private boolean isActive;
}

我做错了什么。请帮帮我

0 个答案:

没有答案