当我尝试级联保存内部集合为“ OneToMany”的所有实体时,它将返回错误。
错误:
o.h.engine.jdbc.spi.SqlExceptionHelper:SQL错误:2291,SQLState:23000 o.h.engine.jdbc.spi.SqlExceptionHelper:ORA-02291:违反完整性约束(MACHINE.OFFICER_FK)-找不到父键
@Entity(name = "GenInfo")
@Table(name = "GEN_INFO")
public class GenInfo {
@Id
@GeneratedValue(generator = "GEN_INFO_SEQ")
@Column(name = "ID_GEN_INFO")
Long id;
@Column(name = "STREET_ADDRESSS")
String streetAddress;
@Column(name = "CITY")
String city;
@Column(name = "STATE_REGION")
String stateOrRegion;
@Column(name = "POSTAL_CODE")
String PostalCode;
@Column(name = "COUNTRY")
String Country;
@Column(name = "CONTACT_NAME")
String ContactName;
@Column(name = "CONTACT_TITLE")
String ContactTitle;
@OneToMany(mappedBy = "genInfo", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
List<Officer> officerCollection;
}
@Entity(name = "Officer")
@Table(name = "OFFICER")
public class Officer {
@Id
@GeneratedValue(generator = "OFFICER_SEQ")
@Column(name = "ID_OFFICER")
Long id;
@Column(name = "OFFICER_NUM")
String officerID;
@Column(name = "PERSON_ID")
String personID;
@Column(name = "OF_RANK")
String rank;
@Column(name = "STATUS")
String status;
@Column(name = "TITLE")
String LongTitle;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "ID_GEN_INFO")
private GenInfo genInfo;
}
这是带有一些休眠信息的日志
Hibernate: insert into gen_info (contact_name, contact_title, country, postal_code, city, state_region, street_addresss, id_gen_info) values (?, ?, ?, ?, ?, ?, ?, ?)
o.h.type.descriptor.sql.BasicBinder : binding parameter [1] as [VARCHAR] - []
o.h.type.descriptor.sql.BasicBinder : binding parameter [2] as [VARCHAR] - []
o.h.type.descriptor.sql.BasicBinder : binding parameter [3] as [VARCHAR] - [France]
o.h.type.descriptor.sql.BasicBinder : binding parameter [4] as [VARCHAR] - [92085]
o.h.type.descriptor.sql.BasicBinder : binding parameter [5] as [VARCHAR] - [PARIS]
o.h.type.descriptor.sql.BasicBinder : binding parameter [6] as [VARCHAR] - []
o.h.type.descriptor.sql.BasicBinder : binding parameter [7] as [VARCHAR] - [Tour W, 102 terrasse Boieldieu]
o.h.type.descriptor.sql.BasicBinder : binding parameter [8] as [BIGINT] - [11]
Hibernate: insert into officer (title, id_gen_info, officer_num, person_id, of_rank, status, id_officer) values (?, ?, ?, ?, ?, ?, ?)
o.h.type.descriptor.sql.BasicBinder : binding parameter [1] as [VARCHAR] - [Chairman of the Board]
o.h.type.descriptor.sql.BasicBinder : binding parameter [2] as [BIGINT] - [11]
o.h.type.descriptor.sql.BasicBinder : binding parameter [3] as [VARCHAR] - [1597265]
o.h.type.descriptor.sql.BasicBinder : binding parameter [4] as [VARCHAR] - [250881]
o.h.type.descriptor.sql.BasicBinder : binding parameter [5] as [VARCHAR] - [1]
o.h.type.descriptor.sql.BasicBinder : binding parameter [6] as [VARCHAR] - [Both]
o.h.type.descriptor.sql.BasicBinder : binding parameter [7] as [BIGINT] - [135]
o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 2291, SQLState: 23000
o.h.engine.jdbc.spi.SqlExceptionHelper : ORA-02291: integrity constraint (MACHINE.OFFICER_FK) violated - parent key not found
答案 0 :(得分:0)
似乎您持有的父键信息
contact_name
表中gen_info
列中的officer
列和officer_id
列中(假定),并试图将一个不匹配的值插入gen_info
中officer.officer_id