当前位置: 首页 > 知识库问答 >
问题:

对象引用未保存的瞬态实例?

羊舌自强
2023-03-14

我有一个数据库,有两个表Batchstatistics和ReconProcessDateTracker。我想了解他们之间的关系。我使用以下模型类使用hibernate实现这一点:

private String batchStatisticsId;
private TblBatch tblBatch;
private Date batchStatisticsStartDateTime;
private Date batchStatisticsEndDateTime;
private String batchStatisticsNumRecordsRead;
private String batchStatisticsNumRecordsAccepted;
private String batchStatisticsNumRecordsRejected;
private String fileName;
private String userCreate;
private Date dateCreate;
private String userModif;
private Date dateModif;
private Set<TblRecordException> tblRecordExceptions = new HashSet<TblRecordException>(
        0);
private Set<TblPgTransactions> tblPgTransactionses = new HashSet<TblPgTransactions>(
        0);
private Set<TblExceptions> tblExceptionses = new HashSet<TblExceptions>(0);
private Set<TblTransactions> tblTransactionses = new HashSet<TblTransactions>(
        0);
private Set<TblKioskStudioTransactions> tblKioskStudioTransactionses = new HashSet<TblKioskStudioTransactions>(
        0);

private Set<TblBillerTransactions> tblBillerTransactionses = new HashSet<TblBillerTransactions>(
        0);
private Set<TblEstateExceptions> tblEstateExceptionses = new HashSet<TblEstateExceptions>(
        0);
private Set<TblEstateTransactionsRepository> tblEstateTransactionsesRepository = new HashSet<TblEstateTransactionsRepository>(
        0);
private Set<TblEstateTransactions> tblEstateTransactionses = new HashSet<TblEstateTransactions>(
        0);

public TblBatchStatistics() {
}

public TblBatchStatistics(String batchStatisticsId) {
    this.batchStatisticsId = batchStatisticsId;
}

public TblBatchStatistics(String batchStatisticsId, TblBatch tblBatch,
        Date batchStatisticsStartDateTime, Date batchStatisticsEndDateTime,
        String batchStatisticsNumRecordsRead,
        String batchStatisticsNumRecordsAccepted,
        String batchStatisticsNumRecordsRejected, String fileName,
        String userCreate, Date dateCreate, String userModif,
        Date dateModif, Set<TblRecordException> tblRecordExceptions,
        Set<TblPgTransactions> tblPgTransactionses,
        Set<TblExceptions> tblExceptionses,
        Set<TblTransactions> tblTransactionses,
        Set<TblKioskStudioTransactions> tblKioskStudioTransactionses,
        Set<TblEstateTransactions> tblEstateTransactionses,
        Set<TblBillerTransactions> tblBillerTransactionses,
        Set<TblEstateTransactionsRepository> tblEstateTransactionsesRepository,
        Set<TblEstateExceptions> tblEstateExceptionses) {
    this.batchStatisticsId = batchStatisticsId;
    this.tblBatch = tblBatch;
    this.batchStatisticsStartDateTime = batchStatisticsStartDateTime;
    this.batchStatisticsEndDateTime = batchStatisticsEndDateTime;
    this.batchStatisticsNumRecordsRead = batchStatisticsNumRecordsRead;
    this.batchStatisticsNumRecordsAccepted = batchStatisticsNumRecordsAccepted;
    this.batchStatisticsNumRecordsRejected = batchStatisticsNumRecordsRejected;
    this.fileName = fileName;
    this.userCreate = userCreate;
    this.dateCreate = dateCreate;
    this.userModif = userModif;
    this.dateModif = dateModif;
    this.tblRecordExceptions = tblRecordExceptions;
    this.tblPgTransactionses = tblPgTransactionses;
    this.tblExceptionses = tblExceptionses;
    this.tblTransactionses = tblTransactionses;
    this.tblKioskStudioTransactionses = tblKioskStudioTransactionses;
    this.tblEstateTransactionses = tblEstateTransactionses;
    this.tblBillerTransactionses = tblBillerTransactionses;
    this.tblEstateTransactionsesRepository = tblEstateTransactionsesRepository;
    this.tblEstateExceptionses = tblEstateExceptionses;
}

@Id
@Column(name = "BatchStatisticsId", unique = true, nullable = false, length = 30)
public String getBatchStatisticsId() {
    return this.batchStatisticsId;
}

public void setBatchStatisticsId(String batchStatisticsId) {
    this.batchStatisticsId = batchStatisticsId;
}

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "BatchId")
public TblBatch getTblBatch() {
    return this.tblBatch;
}

public void setTblBatch(TblBatch tblBatch) {
    this.tblBatch = tblBatch;
}

@Temporal(TemporalType.TIMESTAMP)
@Column(name = "BatchStatisticsStartDateTime", length = 23)
public Date getBatchStatisticsStartDateTime() {
    return this.batchStatisticsStartDateTime;
}

public void setBatchStatisticsStartDateTime(
        Date batchStatisticsStartDateTime) {
    this.batchStatisticsStartDateTime = batchStatisticsStartDateTime;
}

@Temporal(TemporalType.TIMESTAMP)
@Column(name = "BatchStatisticsEndDateTime", length = 23)
public Date getBatchStatisticsEndDateTime() {
    return this.batchStatisticsEndDateTime;
}

public void setBatchStatisticsEndDateTime(Date batchStatisticsEndDateTime) {
    this.batchStatisticsEndDateTime = batchStatisticsEndDateTime;
}

@Column(name = "BatchStatisticsNumRecordsRead", length = 50)
public String getBatchStatisticsNumRecordsRead() {
    return this.batchStatisticsNumRecordsRead;
}

public void setBatchStatisticsNumRecordsRead(
        String batchStatisticsNumRecordsRead) {
    this.batchStatisticsNumRecordsRead = batchStatisticsNumRecordsRead;
}

@Column(name = "BatchStatisticsNumRecordsAccepted", length = 50)
public String getBatchStatisticsNumRecordsAccepted() {
    return this.batchStatisticsNumRecordsAccepted;
}

public void setBatchStatisticsNumRecordsAccepted(
        String batchStatisticsNumRecordsAccepted) {
    this.batchStatisticsNumRecordsAccepted = batchStatisticsNumRecordsAccepted;
}

@Column(name = "BatchStatisticsNumRecordsRejected", length = 50)
public String getBatchStatisticsNumRecordsRejected() {
    return this.batchStatisticsNumRecordsRejected;
}

public void setBatchStatisticsNumRecordsRejected(
        String batchStatisticsNumRecordsRejected) {
    this.batchStatisticsNumRecordsRejected = batchStatisticsNumRecordsRejected;
}

@Column(name = "FileName", length = 50)
public String getFileName() {
    return this.fileName;
}

public void setFileName(String fileName) {
    this.fileName = fileName;
}

@Column(name = "UserCreate", length = 50)
public String getUserCreate() {
    return this.userCreate;
}

public void setUserCreate(String userCreate) {
    this.userCreate = userCreate;
}

@Temporal(TemporalType.TIMESTAMP)
@Column(name = "DateCreate", length = 23)
public Date getDateCreate() {
    return this.dateCreate;
}

public void setDateCreate(Date dateCreate) {
    this.dateCreate = dateCreate;
}

@Column(name = "UserModif", length = 50)
public String getUserModif() {
    return this.userModif;
}

public void setUserModif(String userModif) {
    this.userModif = userModif;
}

@Temporal(TemporalType.TIMESTAMP)
@Column(name = "DateModif", length = 23)
public Date getDateModif() {
    return this.dateModif;
}

public void setDateModif(Date dateModif) {
    this.dateModif = dateModif;
}

@OneToMany(fetch = FetchType.LAZY, mappedBy = "tblBatchStatistics")
public Set<TblRecordException> getTblRecordExceptions() {
    return this.tblRecordExceptions;
}

public void setTblRecordExceptions(
        Set<TblRecordException> tblRecordExceptions) {
    this.tblRecordExceptions = tblRecordExceptions;
}

@OneToMany(fetch = FetchType.LAZY, mappedBy = "tblBatchStatistics")
public Set<TblPgTransactions> getTblPgTransactionses() {
    return this.tblPgTransactionses;
}

public void setTblPgTransactionses(
        Set<TblPgTransactions> tblPgTransactionses) {
    this.tblPgTransactionses = tblPgTransactionses;
}

@OneToMany(fetch = FetchType.LAZY, mappedBy = "tblBatchStatistics")
public Set<TblExceptions> getTblExceptionses() {
    return this.tblExceptionses;
}

public void setTblExceptionses(Set<TblExceptions> tblExceptionses) {
    this.tblExceptionses = tblExceptionses;
}

@OneToMany(fetch = FetchType.LAZY, mappedBy = "tblBatchStatistics")
public Set<TblTransactions> getTblTransactionses() {
    return this.tblTransactionses;
}

public void setTblTransactionses(Set<TblTransactions> tblTransactionses) {
    this.tblTransactionses = tblTransactionses;
}

@OneToMany(fetch = FetchType.LAZY, mappedBy = "tblBatchStatistics")
public Set<TblKioskStudioTransactions> getTblKioskStudioTransactionses() {
    return this.tblKioskStudioTransactionses;
}

public void setTblKioskStudioTransactionses(
        Set<TblKioskStudioTransactions> tblKioskStudioTransactionses) {
    this.tblKioskStudioTransactionses = tblKioskStudioTransactionses;
}


@OneToMany(fetch = FetchType.LAZY, mappedBy = "tblBatchStatistics")
public Set<TblEstateExceptions> getTblEstateExceptionses() {
    return this.tblEstateExceptionses;
}

public void setTblEstateExceptionses(
        Set<TblEstateExceptions> tblEstateExceptionses) {
    this.tblEstateExceptionses = tblEstateExceptionses;
}

@OneToMany(fetch = FetchType.LAZY, mappedBy = "tblBatchStatistics")
public Set<TblEstateTransactionsRepository> getTblEstateTransactionsesRepository() {
    return this.tblEstateTransactionsesRepository;
}

public void setTblEstateTransactionsesRepository(
        Set<TblEstateTransactionsRepository> tblEstateTransactionsesRepository) {
    this.tblEstateTransactionsesRepository = tblEstateTransactionsesRepository;
}

@OneToMany(fetch = FetchType.LAZY, mappedBy = "tblBatchStatistics")
public Set<TblEstateTransactions> getTblEstateTransactionses() {
    return this.tblEstateTransactionses;
}

public void setTblEstateTransactionses(
        Set<TblEstateTransactions> tblEstateTransactionses) {
    this.tblEstateTransactionses = tblEstateTransactionses;
}

@OneToMany(fetch = FetchType.LAZY, mappedBy = "tblBatchStatistics")
public Set<TblBillerTransactions> getTblBillerTransactionses() {
    return this.tblBillerTransactionses;
}

public void setTblBillerTransactionses(
        Set<TblBillerTransactions> tblBillerTransactionses) {
    this.tblBillerTransactionses = tblBillerTransactionses;
}

}

private String reconProcessDateTrackerId;
private TblReconProcessMaster tblReconProcessMaster;
private TblBatchStatistics tblBatchStatistics;
private String fileDate;
private String fileType;
private String uploadDate;
private String userCreate;
private Date dateCreate;
private String userModif;
private Date dateModif;

public TblReconProcessDateTracker() {
}

public TblReconProcessDateTracker(String reconProcessDateTrackerId,
        TblReconProcessMaster tblReconProcessMaster) {
    this.reconProcessDateTrackerId = reconProcessDateTrackerId;
    this.tblReconProcessMaster = tblReconProcessMaster;
}

public TblReconProcessDateTracker(String reconProcessDateTrackerId,
        TblReconProcessMaster tblReconProcessMaster,
        TblBatchStatistics tblBatchStatistics, String fileDate,
        String fileType, String uploadDate, String userCreate,
        Date dateCreate, String userModif, Date dateModif) {
    this.reconProcessDateTrackerId = reconProcessDateTrackerId;
    this.tblReconProcessMaster = tblReconProcessMaster;
    this.tblBatchStatistics = tblBatchStatistics;
    this.fileDate = fileDate;
    this.fileType = fileType;
    this.uploadDate = uploadDate;
    this.userCreate = userCreate;
    this.dateCreate = dateCreate;
    this.userModif = userModif;
    this.dateModif = dateModif;
}

@Id
@Column(name = "ReconProcessDateTrackerId", unique = true, nullable = false, length = 10)
public String getReconProcessDateTrackerId() {
    return this.reconProcessDateTrackerId;
}

public void setReconProcessDateTrackerId(String reconProcessDateTrackerId) {
    this.reconProcessDateTrackerId = reconProcessDateTrackerId;
}

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "ReconProcessId", nullable = false)
public TblReconProcessMaster getTblReconProcessMaster() {
    return this.tblReconProcessMaster;
}

public void setTblReconProcessMaster(
        TblReconProcessMaster tblReconProcessMaster) {
    this.tblReconProcessMaster = tblReconProcessMaster;
}

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "BatchStatisticsId")
public TblBatchStatistics getTblBatchStatistics() {
    return this.tblBatchStatistics;
}

public void setTblBatchStatistics(TblBatchStatistics tblBatchStatistics) {
    this.tblBatchStatistics = tblBatchStatistics;
}

@Column(name = "FileDate", length = 10)
public String getFileDate() {
    return this.fileDate;
}

public void setFileDate(String fileDate) {
    this.fileDate = fileDate;
}

@Column(name = "FileType", length = 10)
public String getFileType() {
    return this.fileType;
}

public void setFileType(String fileType) {
    this.fileType = fileType;
}

@Column(name = "UploadDate", length = 10)
public String getUploadDate() {
    return this.uploadDate;
}

public void setUploadDate(String uploadDate) {
    this.uploadDate = uploadDate;
}

@Column(name = "UserCreate", length = 50)
public String getUserCreate() {
    return this.userCreate;
}

public void setUserCreate(String userCreate) {
    this.userCreate = userCreate;
}

@Temporal(TemporalType.TIMESTAMP)
@Column(name = "DateCreate", length = 23)
public Date getDateCreate() {
    return this.dateCreate;
}

public void setDateCreate(Date dateCreate) {
    this.dateCreate = dateCreate;
}

@Column(name = "UserModif", length = 50)
public String getUserModif() {
    return this.userModif;
}

public void setUserModif(String userModif) {
    this.userModif = userModif;
}

@Temporal(TemporalType.TIMESTAMP)
@Column(name = "DateModif", length = 23)
public Date getDateModif() {
    return this.dateModif;
}

public void setDateModif(Date dateModif) {
    this.dateModif = dateModif;
}

}

当我试图保存它时,我得到的错误对象引用了一个未保存的瞬态实例——在刷新之前保存瞬态实例:com。美国药典。实体TBLBatch统计

共有1个答案

夹谷星河
2023-03-14

如果实体TblReconProcessDateTracker使用之前尚未持久化的TblBatchStatistics持久化,则始终会引发TransientObject异常。

为了解决你的问题你要么

>

使用cascade={CascadeType.PERSIST,CascadeType.MERGE}设置关联级联。您可以在这里找到级联的其他值。这基本上告诉Hibernate,当它试图在TblReconProcessDateTracker上执行这两个操作时,可以持久化/合并TblBatchStatistics的状态。

 类似资料: