object引用未保存的瞬态实例?

时间:2016-02-20 15:39:16

标签: hibernate

我有一个包含两个表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.usp.entity.TblBatchStatistics

1 个答案:

答案 0 :(得分:0)

如果您的实体TransientObjectException与之前尚未保留的TblReconProcessDateTracker持久存在,则始终会抛出TblBatchStatistics

为了解决您的问题,您可以

  1. 在尝试保存TblBatchStatistics个实例之前,请确保您已保留TblReconProcessDateTracker个实例。

  2. 使用cascade = { CascaseType.PERSIST, CascadeType.MERGE }设置关联级联。您可以找到级联的其他值here。 这基本上告诉Hibernate,当TblBatchStatistics尝试执行这两个操作中的任何一个时,保持/合并TblReconProcessDateTracker状态是可以接受的。