错误是:
Caused by : javax.el.ELException: /jsf/submit.xhtml @20,76 listener="#{BankLocationMB.saveLocation}": org.springframework.dao.InvalidDataAccessApiUsageException: org.hibernate.TransientPropertyValueException:
Not-null property references a transient value - transient instance must be saved before current operation : bank.entity.BankLocation.bankFormat -> bank.entity.RefBankFormat;
nested exception is java.lang.IllegalStateException: org.hibernate.TransientPropertyValueException: Not-null property references a transient value - transient instance must be saved before current operation :
bank.entity.BankLocation.bankFormat -> bank.entity.RefBankFormat
@Entity
@Table(name = "BANK_LOCATION", schema = "OWNR")
public class BankLocation implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@NotNull
@Column(name = "BANK_LOCATION_ID")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "BANK_LOCATION_ID_SEQ")
@SequenceGenerator(name = "BANK_LOCATION_ID_SEQ", sequenceName = "OWNR.BANK_LOCATION_ID_SEQ", allocationSize = 1)
private Long bankLocationId;
@Size(max = 32)
@Column(name = "BANK_NAME")
private String bankName;
@JoinColumn(name = "BANK_FORMAT_ID", referencedColumnName = "BANK_FORMAT_ID")
@ManyToOne(targetEntity=RefBankFormat.class, optional = false)
private RefBankFormat bankFormat;
public RefBankFormat getBankFormat() {
return bankFormat;
}
public void setBankFormat(RefBankFormat bankFormat) {
this.bankFormat = bankFormat;
}
@Override
public int hashCode() {
int hash = 0;
hash += (bankLocationId != null ? bankLocationId.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof BankLocation)) {
return false;
}
BankLocation other = (BankLocation) object;
if ((this.bankLocationId == null && other.bankLocationId != null) || (this.bankLocationId != null && !this.bankLocationId.equals(other.bankLocationId))) {
return false;
}
return true;
}
@Override
public String toString() {
return "bank.entity.BankLocation[ bankLocationId=" + bankLocationId + " ]";
}
}
引用表实体
@Entity
@Table(name = "REF_BANK_FORMAT", schema = "OWNR")
public class RefBankFormat implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@NotNull
@Column(name = "BANK_FORMAT_ID")
private Integer bankFormatId;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 50)
@Column(name = "DISPLAY_NAME")
private String displayName;
@Size(max = 50)
@Column(name = "DESCRIPTION")
private String description;
public RefBankFormat() {
}
public RefBankFormat(Integer bankFormatId) {
this.bankFormatId = bankFormatId;
}
public RefBankFormat(Integer bankFormatId, String displayName) {
this.bankFormatId = bankFormatId;
this.displayName = displayName;
}
public Integer getbankFormatId() {
return bankFormatId;
}
public void setbankFormatId(Integer bankFormatId) {
this.bankFormatId = bankFormatId;
}
public String getDisplayName() {
return displayName;
}
public void setDisplayName(String displayName) {
this.displayName = displayName;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
@Override
public int hashCode() {
int hash = 0;
hash += (bankFormatId != null ? bankFormatId.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof RefBankFormat)) {
return false;
}
RefBankFormat other = (RefBankFormat) object;
if ((this.bankFormatId == null && other.bankFormatId != null) || (this.bankFormatId != null && !this.bankFormatId.equals(other.bankFormatId))) {
return false;
}
return true;
}
@Override
public String toString() {
return "bank.entity.RefBankFormat[ bankFormatId=" + bankFormatId + " ]";
}
}
有谁能给我出问题的地方提供解决方案吗?
@ManyToOne(targetEntity=RefBankFormat.class, optional = false)
private RefBankFormat bankFormat;
bankFormat被设置为强制(不是null),因此您必须首先将此对象保存到数据库中,然后才允许保存BankLocation对象。
或
定义传递持久性的策略,也就是级联类型。
我有两个例子。一个是项目,一个是模块。< code >一对多关系。 我将模块设置到项目中。然后使用。第一次,因为数据库中没有记录,所以项目和模块可以保存到数据库中。然而,第二次,因为我不需要创建新项目,我只创建新模块,然后将模块设置回项目。 发生异常。 对象引用未保存的瞬态实例 - 在刷新之前保存瞬态实例。 有什么办法可以解决这个问题吗谢谢
错误是:by:javax.el.elexception://jsf/submit.xhtml@20,76 listener=“#{banklocationmb.savelocation}”对象引用了一个未保存的瞬态实例-在刷新之前保存瞬态实例 尝试添加级联持久化,我收到以下错误 org.springframework.orm.jpa.jpasystemexception:org.hibernate
上图显示了表之间的关系。 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。即使它也会犯