SHARE
TWEET

Untitled

a guest Jun 25th, 2019 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. How to stop hibernate to do select before insert in child table in many to one mapping?
  2.  
  3.     I have a student table :
  4.  
  5.     @Entity
  6.     @Table
  7.     @NoArgsConstructor
  8.     @AllArgsConstructor
  9.     @Builder
  10.     @Data
  11.     @IdClass(StudentId.class)
  12.  
  13.     public class Student implements Persistable<StudentId> {
  14.  
  15.         @Id
  16.         private String studentUuid;
  17.  
  18.         @Id
  19.         private String studentName;
  20.  
  21.         @Column
  22.         private String sex;
  23.  
  24.         public Student(String studentUuid,String studentName){
  25.  
  26.             this.studentUuid = studentUuid;
  27.             this.studentName = studentName;
  28.         }
  29.  
  30.         @ManyToOne(fetch = FetchType.LAZY)
  31.         @JoinColumns({
  32.                 @JoinColumn(
  33.                         name = "classUuid",referencedColumnName = "classUuid"),
  34.                 @JoinColumn(
  35.                         name = "className",referencedColumnName = "className")
  36.         })
  37.         private Class className;
  38.  
  39.  
  40.         @Override
  41.         public StudentId getId() {
  42.             return new StudentId().builder().studentName(studentName).studentUuid(studentUuid).build();
  43.         }
  44.  
  45.         @Override
  46.         public boolean isNew() {
  47.             return true;
  48.         }
  49.     }
  50.      
  51. @Entity
  52. @Table
  53. @Builder
  54. @NoArgsConstructor
  55. @AllArgsConstructor
  56. @Data
  57. @IdClass(ClassId.class)
  58. public class Class implements Persistable<ClassId> {
  59.  
  60.  
  61.     @Id
  62.     private String classUuid;
  63.  
  64.     @Id
  65.     private String className;
  66.  
  67.     @Column
  68.     private String classRoomNo;
  69.  
  70.     @Column
  71.     private String classSize;
  72.  
  73.     @OneToMany(mappedBy = "className",cascade = CascadeType.ALL,fetch = FetchType.LAZY)
  74.     private List<Student> studentList;
  75.  
  76.     @Override
  77.     public ClassId getId() {
  78.         return new ClassId().builder().className(className).classUuid(classUuid).build();
  79.     }
  80.  
  81.     @Override
  82.     public boolean isNew() {
  83.         return true;
  84.     }
  85. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top