无法以@ManyToOne @JoinTable关系保存数据。收到错误消息,指出找不到ID。我是否缺少注释?
我最初有两个表A和B,它们之间存在多对一的关系。我删除了B中的列,并添加了一个字体表A_B,该表具有两个值。现在,我需要在保存B的同时将值保存在A_B中。如果我将ManyToOne输入到ManyToMany中,并且可以在实体B中存储As列表,则可以保存信息。但是一旦是ManyToOne,我就会收到一条错误消息,说未找到b_id
TableA
id
...
TableB
id
....
TableA_B
a_id
b_id
@Entity
public class A extends Model {
@Id
public UUID id;
@OneToMany
@JoinTable(name = "TableA_B",
joinColumns = {@JoinColumn(name = "a_id", insertable = false,
updatable = false, referencedColumnName = "id")},
inverseJoinColumns = {@JoinColumn(name = "B_id", insertable = false,
updatable = false, referencedColumnName = "id")})
public List<B> bs;
}
@Entity
public class B extends Model {
@Id
public UUID id;
@ManyToOne(optional = true)
@JoinTable(name = "TableA_B",
joinColumns = { @JoinColumn(name = "b_id", referencedColumnName = "id")},
inverseJoinColumns = {@JoinColumn(name = "a_id", referencedColumnName = "id")})
public A a;
}
b.save()
Play.api.http.HttpErrorHandlerExceptions $$ anon $ 1:执行例外[[PersistenceException:执行DML bindLog []时出错,错误[字段列表中的未知列'b_id']]]] 在play.api.http.HttpErrorHandlerExceptions $ .throwableToUsefulException(HttpErrorHandler.scala:265)〜[play_2.11-2.4.11.jar:2.4.11] 在play.api.http.DefaultHttpErrorHandler.onServerError(HttpErrorHandler.scala:191)〜[play_2.11-2.4.11.jar:2.4.11] 在play.api.GlobalSettings $ class.onError(GlobalSettings.scala:179)[play_2.11-2.4.11.jar:2.4.11] 在play.core.j.JavaGlobalSettingsAdapter.play $ core $ j $ JavaGlobalSettingsAdapter $$ super $ onError(JavaGlobalSettingsAdapter.scala:36)[play_2.11-2.4.11.jar:2.4.11] 在play.core.j.JavaGlobalSettingsAdapter $$ anonfun $ onError $ 2.apply(JavaGlobalSettingsAdapter.scala:36)[play_2.11-2.4.11.jar:2.4.1