错误是:by:javax.el.elexception://jsf/submit.xhtml@20,76 listener=“#{banklocationmb.savelocation}”对象引用了一个未保存的瞬态实例-在刷新之前保存瞬态实例
尝试添加级联持久化,我收到以下错误
org.springframework.orm.jpa.jpasystemexception:org.hibernate.id.identifiergenerationexception:在调用save():bank.entity.banklocation.refloan之前,必须手动分配该类的ID;嵌套异常是javax.persistence.persistenceException:org.hibernate.id.IdentifierGenerationException:在调用save():bank.entity.bankLocation.refloan之前,必须手动分配该类的ID
@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 = "LOAN_ID", referencedColumnName = "LOAN_ID", insertable = false, updatable = false)
@ManyToOne(targetEntity=RefLoan.class, optional = true)
private RefLoan loan;
public RefLoan getLoan() {
return loan;
}
public void setLoan(RefLoan loan) {
this.loan = loan;
}
@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_LOAN", schema = "OWNR")
public class RefLoan implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@NotNull
@Column(name = "LOAN_ID")
private Integer loanId;
@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 RefLoan() {
}
public RefLoan(Integer loanId) {
this.loanId = loanId;
}
public RefLoan(Integer loanId, String displayName) {
this.loanId = loanId;
this.displayName = displayName;
}
public Integer getLoanId() {
return loanId;
}
public void setLoanId(Integer loanId) {
this.loanId = loanId;
}
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 += (loanId != null ? loanId.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
if (!(object instanceof RefLoan)) {
return false;
}
RefLoan other = (RefLoan) object;
if ((this.loanId == null && other.loanId != null) || (this.loanId != null && !this.loanId.equals(other.loanId))) {
return false;
}
return true;
}
@Override
public String toString() {
return "bank.entity.RefLoan[ loanId=" + loanId + " ]";
}
}
有谁能给我出问题的地方提供解决方案吗?
谢谢
这是错误消息的重要部分:在调用save():bank.entity.banklocation.refloan之前,必须手动分配此类的ID
在
refloan
类中,ID没有标记为自动生成:
@Id
@Basic(optional = false)
@NotNull
@Column(name = "LOAN_ID")
private Integer loanId;
您需要添加您在BankLocation类中使用的注释(在相应地调整序列的名称之后)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "BANK_LOCATION_ID_SEQ")
@SequenceGenerator(name = "BANK_LOCATION_ID_SEQ", sequenceName = "OWNR.BANK_LOCATION_ID_SEQ", allocationSize = 1)
错误: 我还尝试了,但是 病因是什么?显然,我设置了nullable=true(在数据库中也是如此),尽管我有这个错误。有什么想法吗?
我正在使用Seam Framework。我有2个实体: Request.java 和请求事件.java 当我进行此交易时: 我得到了这个错误:
我有两个例子。一个是项目,一个是模块。< code >一对多关系。 我将模块设置到项目中。然后使用。第一次,因为数据库中没有记录,所以项目和模块可以保存到数据库中。然而,第二次,因为我不需要创建新项目,我只创建新模块,然后将模块设置回项目。 发生异常。 对象引用未保存的瞬态实例 - 在刷新之前保存瞬态实例。 有什么办法可以解决这个问题吗谢谢
上图显示了表之间的关系。 AddressType表包含静态值,如mailing、home、work等。 在AddressTypeRel模型类中,我有一个带有多对一注释的AddressType对象
user.java是 我正在使用这个视频中提到的存储库,是 和 这个问题有什么更好的解决办法吗?
我试图将用户详细信息存储到以下表中:user、role、user_role。当试图保存详细信息时,它会引发以下错误。 托管刷新时出错[org.hibernate.transientPropertyValueException:object引用未保存的瞬态实例-在刷新前保存瞬态实例 这里user_role是父表,user和role表是子表。我尝试了cascade=cascade.all。即使它也会犯