我在spring boot中遇到这个错误:
试图从空一对一属性中分配 id [com.endoorment.models.entity.ActionLang.action]
我的代码:
@Embeddable
public class ActionLangId implements Serializable {
private static final long serialVersionUID = 1 L;
@NotNull
@Column(name = "actions_id")
private Integer actionId;
@NotNull
@Column(name = "langs_id")
private Integer langId;
public ActionLangId() {}
public ActionLangId(Integer actionId, Integer langId) {
super();
this.actionId = actionId;
this.langId = langId;
}
public Integer getActionId() {
return actionId;
}
public void setActionId(Integer actionId) {
this.actionId = actionId;
}
public Integer getLangId() {
return langId;
}
public void setLangId(Integer langId) {
this.langId = langId;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass())
return false;
ActionLangId that = (ActionLangId) o;
return Objects.equals(actionId, that.actionId) &&
Objects.equals(langId, that.langId);
}
@Override
public int hashCode() {
return Objects.hash(actionId, langId);
}
}
@Entity
@Table(name = "actions_langs")
public class ActionLang {
@EmbeddedId
private ActionLangId id;
@ManyToOne(fetch = FetchType.LAZY)
@MapsId("actionId")
@JoinColumn(name = "actions_id")
private Action action;
@ManyToOne(fetch = FetchType.LAZY)
@MapsId("langId")
@JoinColumn(name = "langs_id")
private Lang lang;
@NotNull(message = "null")
@Size(max = 45, message = "short")
private String name;
public ActionLang() {}
public ActionLang(ActionLangId actionlangid, String name) {
this.id = actionlangid;
this.name = name;
}
public ActionLangId getId() {
return id;
}
public void setId(ActionLangId id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return "ActionLang [id=" + id + ", name=" + name + "]";
}
}
青春有我
隔江千里
幕布斯7119047
相关分类