我有一个数据库,有两个表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统计
如果实体TblReconProcessDateTracker
使用之前尚未持久化的TblBatchStatistics
持久化,则始终会引发TransientObject异常。
为了解决你的问题你要么
>
使用
cascade={CascadeType.PERSIST,CascadeType.MERGE}
设置关联级联。您可以在这里找到级联的其他值。这基本上告诉Hibernate,当它试图在TblReconProcessDateTracker
上执行这两个操作时,可以持久化/合并TblBatchStatistics
的状态。
我有两个例子。一个是项目,一个是模块。< code >一对多关系。 我将模块设置到项目中。然后使用。第一次,因为数据库中没有记录,所以项目和模块可以保存到数据库中。然而,第二次,因为我不需要创建新项目,我只创建新模块,然后将模块设置回项目。 发生异常。 对象引用未保存的瞬态实例 - 在刷新之前保存瞬态实例。 有什么办法可以解决这个问题吗谢谢
上图显示了表之间的关系。 AddressType表包含静态值,如mailing、home、work等。 在AddressTypeRel模型类中,我有一个带有多对一注释的AddressType对象
错误: 我还尝试了,但是 病因是什么?显然,我设置了nullable=true(在数据库中也是如此),尽管我有这个错误。有什么想法吗?
user.java是 我正在使用这个视频中提到的存储库,是 和 这个问题有什么更好的解决办法吗?
我试图将用户详细信息存储到以下表中:user、role、user_role。当试图保存详细信息时,它会引发以下错误。 托管刷新时出错[org.hibernate.transientPropertyValueException:object引用未保存的瞬态实例-在刷新前保存瞬态实例 这里user_role是父表,user和role表是子表。我尝试了cascade=cascade.all。即使它也会犯
在baseEntity中具有Id