Когда я пытаюсь сохранить с каскадом все сущности с коллекцией внутри, установленной как «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