Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.62 KB | None | 0 0
  1. Caused by: org.postgresql.util.PSQLException: ERROR: insert or update on table "order" violates foreign key constraint "fk1w50d63tw42cwgrb7pjn11crs"
  2. Detail: Key (id_office_o, id_period)=(2, 1) is not present in table "office".
  3.  
  4. CREATE TABLE period (
  5. id_period INTEGER PRIMARY KEY NOT NULL,
  6. initial_date TIMESTAMP,
  7. final_date TIMESTAMP
  8. );
  9.  
  10. CREATE TABLE office (
  11. id_period INTEGER NOT NULL,
  12. id_office INTEGER NOT NULL,
  13. large_name VARCHAR(50) NOT NULL,
  14. code_name VARCHAR(2) NOT NULL,
  15. CONSTRAINT pk_office PRIMARY KEY (id_periodo, id_office),
  16. CONSTRAINT fk_office_period FOREIGN KEY (id_period) REFERENCES period (id_period)
  17. );
  18. CREATE UNIQUE INDEX uk_office_id_office ON office (id_office);
  19.  
  20. CREATE TABLE order (
  21. id_order INTEGER PRIMARY KEY NOT NULL,
  22. id_period INTEGER,
  23. id_office_o INTEGER,
  24. id_office_d INTEGER,
  25. status INTEGER,
  26. CONSTRAINT fk_order_office_o
  27. FOREIGN KEY (id_period, id_office_o)
  28. REFERENCES office (id_period, id_office)
  29. MATCH SIMPLE ON UPDATE CASCADE ON DELETE RESTRICT,
  30. CONSTRAINT fk_order_office_d
  31. FOREIGN KEY (id_period, id_office_d)
  32. REFERENCES office (id_period, id_office),
  33. MATCH SIMPLE ON UPDATE CASCADE ON DELETE RESTRICT,
  34. CONSTRAINT fk_order_period
  35. FOREIGN KEY (id_period)
  36. REFERENCES period (id_period)
  37. MATCH SIMPLE ON UPDATE CASCADE ON DELETE RESTRICT
  38. );
  39.  
  40. Period.
  41. +------------+--------------+------------+
  42. | id_period | initial_date | final_date |
  43. |------------|--------------|------------+
  44. | 1 | 2016-01-01 | 2017-12-31 |
  45. +------------+--------------+------------+
  46.  
  47. Office.
  48. +------------+-----------+------------+-----------+
  49. | id_period | id_office | large_name | code_name |
  50. |------------|-----------|------------|-----------|
  51. | 1 | 1 | Sales | SL |
  52. | 1 | 2 | Billing | BL |
  53. | 1 | 3 | Shipments | SH |
  54. | 1 | 4 | Returns | RT |
  55. +------------+-----------+------------+-----------+
  56.  
  57. Order.
  58. +------------+-----------+--------------+--------------+-----------+
  59. | id_order | id_period | id_office_o | id_office_d | status |
  60. +------------+-----------+--------------+--------------+-----------+
  61. | 1 | 1 | 2 | 3 | 1 |
  62. | 2 | 1 | 2 | 3 | 1 |
  63. | 1 | 1 | 3 | 4 | 1 |
  64. | 1 | 1 | 1 | 2 | 1 |
  65. +------------+-----------+--------------+--------------+-----------+
  66.  
  67. @Embeddable
  68. public class OfficePK implements Serializable {
  69.  
  70. @ManyToOne
  71. @JoinColumn(name = "id_period")
  72. private Integer idPeriod;
  73.  
  74. @Column(name="id_office")
  75. private Integer idOffice;
  76.  
  77. public OfficePK() {
  78. }
  79.  
  80. public OfficePK(Integer idPeriod, Integer idOffice) {
  81. this.idPeriod = idPeriod;
  82. this.idOffice = idOffice;
  83. }
  84.  
  85. ...
  86.  
  87. }
  88.  
  89.  
  90. @Entity
  91. @Table(schema="enterprise", name="office")
  92. public class Office {
  93.  
  94.  
  95. @EmbeddedId
  96. private OfficePK idOffice;
  97.  
  98. private String largeName;
  99. private String codeName;
  100.  
  101. public Office() {
  102. }
  103.  
  104. public OfficePK getIdOffice() {
  105. return this.idOffice;
  106. }
  107.  
  108. public void setIdOffice(OfficePK idOffice) {
  109. this.idOffice = idOffice;
  110. }
  111.  
  112. ...
  113.  
  114. }
  115.  
  116.  
  117. @Entity
  118. @Table(schema="operation", name = "order")
  119. public class Ficha {
  120.  
  121. @Column(name="id_order")
  122. private Integer idOrder;
  123.  
  124. @ManyToOne
  125. @JoinColumns(
  126. value = {
  127. @JoinColumn(name="id_period",
  128. referencedColumnName = "id_period",
  129. nullable = false, insertable = false,
  130. updatable = false),
  131. @JoinColumn(name="id_office_o",
  132. referencedColumnName = "id_office",
  133. nullable = false, insertable = false,
  134. updatable = false)
  135. },
  136. foreignKey = @ForeignKey(name = "fk_order_office_o")
  137. )
  138. private officeO;
  139.  
  140. @ManyToOne
  141. @JoinColumns(
  142. value = {
  143. @JoinColumn(name="id_period",
  144. referencedColumnName = "id_period",
  145. nullable = false, insertable = false,
  146. updatable = false),
  147. @JoinColumn(name="id_office_d",
  148. referencedColumnName = "id_office",
  149. nullable = false, insertable = false,
  150. updatable = false)
  151. },
  152. foreignKey = @ForeignKey(name = "fk_order_office_d")
  153. )
  154. private officeD;
  155.  
  156. public Order() {
  157. }
  158.  
  159. ...
  160.  
  161. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement