Guest User

Untitled

a guest
Jul 25th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.52 KB | None | 0 0
  1. org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL via JDBC Statement
  2.  
  3. Caused by: java.sql.SQLException: Cannot add foreign key constraint
  4.  
  5. package com.example.WebAppProcess20.Entities;
  6.  
  7. import javax.persistence.*;
  8. import java.util.Objects;
  9.  
  10. @Entity
  11. @Table(name = "ordersitems", schema = "theprocess")
  12. @IdClass(OrdersitemsEntityPK.class)
  13. public class OrdersitemsEntity {
  14. private String orderId;
  15. private String productId;
  16. private Integer qunatity;
  17. private OrdersEntity ordersByOrderId;
  18.  
  19. @Id
  20. @Column(name = "orderId")
  21. public String getOrderId() {
  22. return orderId;
  23. }
  24.  
  25. public void setOrderId(String orderId) {
  26. this.orderId = orderId;
  27. }
  28.  
  29. @Id
  30. @Column(name = "product_id")
  31. public String getProductId() {
  32. return productId;
  33. }
  34.  
  35. public void setProductId(String productId) {
  36. this.productId = productId;
  37. }
  38.  
  39. @Basic
  40. @Column(name = "qunatity")
  41. public Integer getQunatity() {
  42. return qunatity;
  43. }
  44.  
  45. public void setQunatity(Integer qunatity) {
  46. this.qunatity = qunatity;
  47. }
  48.  
  49. @Override
  50. public boolean equals(Object o) {
  51. if (this == o) return true;
  52. if (o == null || getClass() != o.getClass()) return false;
  53. OrdersitemsEntity that = (OrdersitemsEntity) o;
  54. return Objects.equals(orderId, that.orderId) &&
  55. Objects.equals(productId, that.productId) &&
  56. Objects.equals(qunatity, that.qunatity);
  57. }
  58.  
  59. @Override
  60. public int hashCode() {
  61.  
  62. return Objects.hash(orderId, productId, qunatity);
  63. }
  64.  
  65. @ManyToOne
  66. @JoinColumn(name = "orderId", referencedColumnName = "orderId", nullable = false, updatable = false, insertable = false)
  67. public OrdersEntity getOrdersByOrderId() {
  68. return ordersByOrderId;
  69. }
  70.  
  71. public void setOrdersByOrderId(OrdersEntity ordersByOrderId) {
  72. this.ordersByOrderId = ordersByOrderId;
  73. }
  74. }
  75.  
  76. <?xml version='1.0' encoding='utf-8'?>
  77.  
  78. <!DOCTYPE hibernate-configuration PUBLIC
  79. "-//Hibernate/Hibernate Configuration DTD//EN"
  80. "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
  81. <hibernate-configuration>
  82. <session-factory>
  83. <property name="connection.url">jdbc:mysql://localhost:3306/theprocess?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC</property>
  84. <property name="connection.driver_class">com.mysql.cj.jdbc.Driver</property>
  85. <property name="connection.username">root</property>
  86. <property name="connection.password">root</property>
  87. <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
  88. <!-- DB schema will be updated if needed -->
  89. <property name="hbm2ddl.auto">update</property>
  90. <mapping class="com.example.WebAppProcess20.Entities.ClientsEntity"/>
  91. <mapping class="com.example.WebAppProcess20.Entities.InvoicesEntity"/>
  92. <mapping class="com.example.WebAppProcess20.Entities.OrdersEntity"/>
  93. <mapping class="com.example.WebAppProcess20.Entities.OrdersitemsEntity"/>
  94. <mapping class="com.example.WebAppProcess20.Entities.ProductsEntity"/>
  95. </session-factory>
  96. </hibernate-configuration>
  97.  
  98. <?xml version="1.0" encoding="UTF-8"?>
  99. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  100. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  101. <modelVersion>4.0.0</modelVersion>
  102.  
  103. <groupId>com.example</groupId>
  104. <artifactId>WebAppProcess2.0</artifactId>
  105. <version>0.0.1-SNAPSHOT</version>
  106. <packaging>jar</packaging>
  107.  
  108. <name>WebAppProcess2.0</name>
  109. <description>Demo project for Spring Boot</description>
  110.  
  111. <parent>
  112. <groupId>org.springframework.boot</groupId>
  113. <artifactId>spring-boot-starter-parent</artifactId>
  114. <version>2.0.2.RELEASE</version>
  115. <relativePath/> <!-- lookup parent from repository -->
  116. </parent>
  117.  
  118. <properties>
  119. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  120. <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  121. <java.version>1.8</java.version>
  122. </properties>
  123.  
  124. <dependencies>
  125. <dependency>
  126. <groupId>org.springframework.boot</groupId>
  127. <artifactId>spring-boot-starter-actuator</artifactId>
  128. </dependency>
  129. <dependency>
  130. <groupId>org.springframework.boot</groupId>
  131. <artifactId>spring-boot-starter-data-jpa</artifactId>
  132. </dependency>
  133.  
  134. <dependency>
  135. <groupId>org.springframework.boot</groupId>
  136. <artifactId>spring-boot-starter-web</artifactId>
  137. </dependency>
  138.  
  139. <dependency>
  140. <groupId>org.springframework.boot</groupId>
  141. <artifactId>spring-boot-starter-test</artifactId>
  142. <scope>test</scope>
  143. </dependency>
  144. <dependency>
  145. <groupId>mysql</groupId>
  146. <artifactId>mysql-connector-java</artifactId>
  147. <version>8.0.11</version>
  148. </dependency>
  149. <!-- https://mvnrepository.com/artifact/org.springframework/spring-jdbc -->
  150. <dependency>
  151. <groupId>org.springframework</groupId>
  152. <artifactId>spring-jdbc</artifactId>
  153. <version>5.0.7.RELEASE</version>
  154. </dependency>
  155. </dependencies>
  156.  
  157. <build>
  158. <plugins>
  159. <plugin>
  160. <groupId>org.springframework.boot</groupId>
  161. <artifactId>spring-boot-maven-plugin</artifactId>
  162. </plugin>
  163. </plugins>
  164. </build>
  165.  
  166.  
  167. </project>
Add Comment
Please, Sign In to add comment