Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Caused by: org.postgresql.util.PSQLException: ERROR: insert or update on table "order" violates foreign key constraint "fk1w50d63tw42cwgrb7pjn11crs"
- Detail: Key (id_office_o, id_period)=(2, 1) is not present in table "office".
- CREATE TABLE period (
- id_period INTEGER PRIMARY KEY NOT NULL,
- initial_date TIMESTAMP,
- final_date TIMESTAMP
- );
- CREATE TABLE office (
- id_period INTEGER NOT NULL,
- id_office INTEGER NOT NULL,
- large_name VARCHAR(50) NOT NULL,
- code_name VARCHAR(2) NOT NULL,
- CONSTRAINT pk_office PRIMARY KEY (id_periodo, id_office),
- CONSTRAINT fk_office_period FOREIGN KEY (id_period) REFERENCES period (id_period)
- );
- CREATE UNIQUE INDEX uk_office_id_office ON office (id_office);
- CREATE TABLE order (
- id_order INTEGER PRIMARY KEY NOT NULL,
- id_period INTEGER,
- id_office_o INTEGER,
- id_office_d INTEGER,
- status INTEGER,
- CONSTRAINT fk_order_office_o
- FOREIGN KEY (id_period, id_office_o)
- REFERENCES office (id_period, id_office)
- MATCH SIMPLE ON UPDATE CASCADE ON DELETE RESTRICT,
- CONSTRAINT fk_order_office_d
- FOREIGN KEY (id_period, id_office_d)
- REFERENCES office (id_period, id_office),
- MATCH SIMPLE ON UPDATE CASCADE ON DELETE RESTRICT,
- CONSTRAINT fk_order_period
- FOREIGN KEY (id_period)
- REFERENCES period (id_period)
- MATCH SIMPLE ON UPDATE CASCADE ON DELETE RESTRICT
- );
- Period.
- +------------+--------------+------------+
- | id_period | initial_date | final_date |
- |------------|--------------|------------+
- | 1 | 2016-01-01 | 2017-12-31 |
- +------------+--------------+------------+
- Office.
- +------------+-----------+------------+-----------+
- | id_period | id_office | large_name | code_name |
- |------------|-----------|------------|-----------|
- | 1 | 1 | Sales | SL |
- | 1 | 2 | Billing | BL |
- | 1 | 3 | Shipments | SH |
- | 1 | 4 | Returns | RT |
- +------------+-----------+------------+-----------+
- Order.
- +------------+-----------+--------------+--------------+-----------+
- | id_order | id_period | id_office_o | id_office_d | status |
- +------------+-----------+--------------+--------------+-----------+
- | 1 | 1 | 2 | 3 | 1 |
- | 2 | 1 | 2 | 3 | 1 |
- | 1 | 1 | 3 | 4 | 1 |
- | 1 | 1 | 1 | 2 | 1 |
- +------------+-----------+--------------+--------------+-----------+
- @Embeddable
- public class OfficePK implements Serializable {
- @ManyToOne
- @JoinColumn(name = "id_period")
- private Integer idPeriod;
- @Column(name="id_office")
- private Integer idOffice;
- public OfficePK() {
- }
- public OfficePK(Integer idPeriod, Integer idOffice) {
- this.idPeriod = idPeriod;
- this.idOffice = idOffice;
- }
- ...
- }
- @Entity
- @Table(schema="enterprise", name="office")
- public class Office {
- @EmbeddedId
- private OfficePK idOffice;
- private String largeName;
- private String codeName;
- public Office() {
- }
- public OfficePK getIdOffice() {
- return this.idOffice;
- }
- public void setIdOffice(OfficePK idOffice) {
- this.idOffice = idOffice;
- }
- ...
- }
- @Entity
- @Table(schema="operation", name = "order")
- public class Ficha {
- @Column(name="id_order")
- private Integer idOrder;
- @ManyToOne
- @JoinColumns(
- value = {
- @JoinColumn(name="id_period",
- referencedColumnName = "id_period",
- nullable = false, insertable = false,
- updatable = false),
- @JoinColumn(name="id_office_o",
- referencedColumnName = "id_office",
- nullable = false, insertable = false,
- updatable = false)
- },
- foreignKey = @ForeignKey(name = "fk_order_office_o")
- )
- private officeO;
- @ManyToOne
- @JoinColumns(
- value = {
- @JoinColumn(name="id_period",
- referencedColumnName = "id_period",
- nullable = false, insertable = false,
- updatable = false),
- @JoinColumn(name="id_office_d",
- referencedColumnName = "id_office",
- nullable = false, insertable = false,
- updatable = false)
- },
- foreignKey = @ForeignKey(name = "fk_order_office_d")
- )
- private officeD;
- public Order() {
- }
- ...
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement