Guest User

Untitled

a guest
Jul 31st, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 KB | None | 0 0
  1. @Entity
  2. @Getter
  3. @Setter
  4. @Table(name = "Question")
  5. public class Question {
  6.  
  7. @Id
  8. @GeneratedValue(strategy = GenerationType.IDENTITY)
  9. private int id;
  10.  
  11. @Column(length = 128)
  12. private String name;
  13.  
  14. @OneToMany(mappedBy = "question", cascade = CascadeType.ALL, orphanRemoval = true)
  15. private List<QuestionAnswerMapping> questionAnswerMapping;
  16. }
  17.  
  18. @Entity
  19. @Getter
  20. @Setter
  21. @Table(name = "Answer")
  22. public class Answer {
  23. @Id
  24. @GeneratedValue(strategy = GenerationType.IDENTITY)
  25. private int id;
  26.  
  27. @Column(length = 255)
  28. private String displayText;
  29.  
  30. @OneToMany(mappedBy = "answer")
  31. private List<QuestionAnswerMapping> questionAnswerMapping;
  32. }
  33.  
  34. @Entity
  35. @Table(name = "Question_Answer_Mapping")
  36. public class QuestionAnswerMapping {
  37.  
  38. @Id
  39. @GeneratedValue(strategy = GenerationType.IDENTITY)
  40. private int id;
  41.  
  42. @ManyToOne
  43. @JoinColumn(name="questionId", nullable = false /*, referencedColumnName="id" , foreignKey=@ForeignKey(name="FK_Question", value=ConstraintMode.CONSTRAINT)*/)
  44. /* @JoinColumns(value = { @JoinColumn(name="questionId",referencedColumnName="id",foreignKey=@ForeignKey(value=ConstraintMode.CONSTRAINT)) }) */
  45. private Question question;
  46.  
  47. @ManyToOne
  48. @JoinColumn(name="answerId", nullable = false /*, referencedColumnName="id", foreignKey=@ForeignKey(name="FK_Answer", value=ConstraintMode.CONSTRAINT)*/)
  49. /* @JoinColumns(value = { @JoinColumn(name="answerId",referencedColumnName="id",foreignKey=@ForeignKey(value=ConstraintMode.CONSTRAINT)) }) */
  50. private Answer answer;
  51.  
  52. }
  53.  
  54. ---
  55. spring:
  56. profiles: local
  57.  
  58. datasource:
  59. url: jdbc:mysql://localhost:3306/test?useSSL=false
  60. username: root
  61.  
  62. jpa:
  63. generate-ddl: true
  64. show-sql: true
  65. hibernate:
  66. naming:
  67. physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
  68. properties:
  69. hibernate:
  70. dialect: org.hibernate.dialect.MySQL5Dialect
  71. ddl-auto: create-drop
  72.  
  73. CREATE TABLE `question` (
  74. `id` int(11) NOT NULL AUTO_INCREMENT,
  75. `name` varchar(128) DEFAULT NULL,
  76. PRIMARY KEY (`id`)
  77. ) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
  78.  
  79.  
  80. CREATE TABLE `answer` (
  81. `id` int(11) NOT NULL AUTO_INCREMENT,
  82. `displayText` varchar(255) DEFAULT NULL,
  83. PRIMARY KEY (`id`)
  84. ) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
  85.  
  86.  
  87. CREATE TABLE `question_answer_mapping` (
  88. `id` int(11) NOT NULL AUTO_INCREMENT,
  89. `answerId` int(11) NOT NULL,
  90. `questionId` int(11) NOT NULL,
  91. PRIMARY KEY (`id`),
  92. KEY `FKpjg76y4ofqmvfmbujphnqyq1y` (`answerId`),
  93. KEY `FK2mbyguxt74rwhv1n1t11wi3fl` (`questionId`)
  94. ) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
Add Comment
Please, Sign In to add comment