我在使用这个 @ManyToOne 地图时遇到了问题,搜索了很多,但仍然找不到解决此问题的方法。
我有这两个类,我永远不会在 TB_MANUAL 中插入任何东西,我只是将它用作 TB_COMPANY 中 CD_MANUAL 字段的参考,如下所示:
Company company = new Company();
company.setManual("2"); //Theres already a row with this id in the TB_MANUAL
然后坚持公司,但我收到了这个错误:
Caused By: java.lang.IllegalStateException: During synchronization a new object was found through a relationship that was not marked cascade PERSIST: 2.
at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.discoverUnregisteredNewObjects(RepeatableWriteUnitOfWork.java:313)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.calculateChanges(UnitOfWorkImpl.java:723)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitToDatabaseWithChangeSet(UnitOfWorkImpl.java:1516)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.issueSQLbeforeCompletion(UnitOfWorkImpl.java:3168)
at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.issueSQLbeforeCompletion(RepeatableWriteUnitOfWork.java:355)
Truncated. see log file for complete stacktrace
——
@Entity
@Table(name = "TB_COMPANY", schema = "ADMPROD")
@Cacheable
public class Company implements Serializable {
private static final long serialVersionUID = 1L;
public Company() {}
public Company(String id) {
this.id = id;
}
@ManyToOne
@JoinColumn(name = "CD_MANUAL", referencedColumnName = "CD_MANUAL", nullable
= true)
private Manual manual;
public void setManual(String idManual) {
this.manual = new Manual(idManual);
}
}
和
@Entity
@Table(name = "TB_MANUAL")
public class Manual implements Serializable{
private static final long serialVersionUID = 1L;
public Manual() {
}
public Manual(String id) {
this.id = id;
}
@Id
@Column(name = "CD_MANUAL")
private String id;
@Column(name = "DS_OBS_MANUAL")
private String description;
}
沧海一幻觉
相关分类