gpt4 book ai didi

java - 违反完整性约束 - 在级联上找不到父 key

转载 作者:行者123 更新时间:2023-12-02 05:35:44 24 4
gpt4 key购买 nike

当我尝试级联保存所有内部集合设置为“OneToMany”的实体时,它会返回错误。

错误:

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

@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 信息的日志

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

最佳答案

您似乎持有父 key 信息名为 officer 的表中的 gen_info 表的 contact_name 列和名为 officer_id 的列(假设),并尝试插入gen_info 中的值与 officer.officer_id

没有匹配的值

关于java - 违反完整性约束 - 在级联上找不到父 key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56167903/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com