I am trying to parse a web request and save to database. I have 3 models and first node is virtualDocument. This is the uniq table (according to request url). VirtualRequest table has all erquest bodies and HttpHeaderList table has all thhp headers according to their virtualRequest bean id.
when I tried to save the first log I got and error like this;
org.h2.jdbc.JdbcSQLException: Referential integrity constraint violation: "FK1TW2G47F7A47580KQVMDJWGBQ: PUBLIC.T_VIRTUAL_REQUEST FOREIGN KEY(REQUEST_ID) REFERENCES PUBLIC.T_VIRTUAL_DOCUMENT(DOCUMENT_ID) (65)"; SQL statement:
insert into t_virtual_request (request_id, media_type, method_type, request_url) values (null, ?, ?, ?) [23506-192]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:345) ~[h2-1.4.192.jar:1.4.192]
here is VirtualDocument bean
@Entity
@Table(name = "t_virtual_document")
public class VirtualDocument {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "document_id")
private long documentId;
@Column(name = "real_url", unique = true)
private String realURL; //uniq
@Column(name = "virtual_url", unique = true)
private String virtualURL; //uniq
@Column(name = "simulation_mode", columnDefinition = "varchar(10) default 'STOP'")
private String simulationMode;
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "request_id")
private List<VirtualRequest> requestList;
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "response_id")
private List<VirtualResponse> responseList;
//getter setter without any annotation
}
here is VirtualRequest bean;
@Entity
@Table(name = "t_virtual_request")
public class VirtualRequest {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "request_id")
private long requestId;
@Column(name = "request_url")
private String requestURL;
@Column(name = "method_type")
private String methodType;
@Column(name = "media_type")
private String mediaType;
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "header_id")
private List<HttpHeaderList> requestHeaders;
//getter setter without any annotation
}
here is HeaderList bean;
@Entity
@Table(name = "t_http_headers")
public class HttpHeaderList {
@Id
@Column(name = "header_id")
private long headerId;
@Column(name = "header_key")
private String headerKey;
@Column(name = "header_value")
private String headerValue;
}
I think this is what you want instead:
Updated the answer to add mapping the headers to the request entity.