hibernate-在调用save之前,必须手动分配此类的ID
对象引用未保存的临时示例-刷新前保存临时示例
我的xhtml页面中有一个下拉选项。有时用户需要选择此下拉列表,
有时他不需要选择下拉值。
我有两个相关的实体,一个是主表,一个列(null)在主表中有一个引用表。我正试图把数据保存在表中。
错误是:由:javax.el.elexception:/jsf/submit.xhtml@20,76 listener=“#{banklocationmb.savelocation}”对象引用了未保存的临时示例-在刷新之前保存临时示例
尝试添加层叠,但收到以下错误
org.springframework.orm.jpa.jpasystemexception:org.hibernate.id.identifiergenerationexception:调用save()之前必须手动分配此类的id:bank.entity.banklocation.refloan;嵌套的异常是javax.persistence.persistenceexception:org.hibernate.id.identigergenerationexception:调用save()之前必须手动分配此类的id:bank.entity.banklocation.refloan
@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 + " ]";
}
}
有人能帮我解决哪里出了问题吗?
谢谢
2条答案
按热度按时间bd1hkmkf1#
这是错误消息的重要部分:
ids for this class must be manually assigned before calling save(): bank.entity.BankLocation.RefLoan
在你的Refloan
类id未标记为自动生成:您需要添加在banklocation类中使用的注解(在相应地调整序列名称之后)
egmofgnx2#
您可能有以下类似的代码:
您必须为贷款使用托管引用,如下所示: