daily pastebin goal
94%
SHARE
TWEET

Untitled

a guest Jun 14th, 2018 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @Entity
  2. public class User {
  3.  
  4.     @Id
  5.     @GeneratedValue(strategy = GenerationType.AUTO)
  6.     private Long id;
  7.  
  8.     @ManyToMany(
  9.             cascade = {CascadeType.PERSIST, CascadeType.MERGE},
  10.             fetch = FetchType.EAGER)
  11.     @JoinTable(
  12.             name = "user_role",
  13.             joinColumns = @JoinColumn(name = "user_id"),
  14.             inverseJoinColumns = @JoinColumn(name = "role_id"))
  15.     private Set<Role> roles;
  16.  
  17.     // other fields, constructors, getters/setters
  18. }
  19.    
  20. @Entity
  21. public class Role {
  22.  
  23.     @Id
  24.     @GeneratedValue(strategy = GenerationType.AUTO)
  25.     private Long id;
  26.  
  27.     @ManyToMany(mappedBy = "roles")
  28.     private Set<User> users;
  29.  
  30.     // other fields, constructors, getters/setters
  31. }
  32.    
  33. @Entity
  34. public class Order {
  35.  
  36.     @Id
  37.     @GeneratedValue(strategy = GenerationType.AUTO)
  38.     private Long id;
  39.  
  40.     @ManyToOne(optional = false)
  41.     @JoinColumn(name = "user_id")
  42.     private User submitter;
  43.     @ManyToOne(optional = false)
  44.     @JoinColumn(name = "user_id")
  45.     private User approver;
  46.  
  47.     // other fields, constructors, getters/setters
  48. }
  49.    
  50. @Entity
  51. public class Order {
  52.  
  53.     // id, submitter, approver fields, see in previous snippet
  54.  
  55.     @OneToMany(mappedBy = "order", cascade = CascadeType.ALL)
  56.     private Set<OrderItem> items;
  57.  
  58.     // other fields, constructors, getters/setters
  59. }
  60.    
  61. @Entity
  62. public class OrderItem {
  63.  
  64.     @Id
  65.     @GeneratedValue(strategy = GenerationType.AUTO)
  66.     private Long id;
  67.  
  68.     @ManyToOne(fetch = FetchType.LAZY)
  69.     @JoinColumn(name = "order_item_id")
  70.     private Order order;
  71.  
  72.     // other fields, constructors, getters/setters
  73. }
  74.    
  75. @Entity
  76. public class Order {
  77.  
  78.     // fields from previous snippets
  79.  
  80.     @OneToMany(mappedBy = "order", cascade = CascadeType.ALL)
  81.     private Set<OrderAttachment> attachments;
  82.  
  83.     // other fields, constructors, getters/setters
  84. }
  85.    
  86. @Entity
  87. public class OrderAttachment {
  88.  
  89.     @Id
  90.     @GeneratedValue(strategy = GenerationType.AUTO)
  91.     private Long id;
  92.  
  93.     private String fileName;
  94.  
  95.     @ManyToOne(fetch = FetchType.LAZY)
  96.     @JoinColumn(name = "order_attachment_id")
  97.     private Order order;
  98.  
  99.     @Lob
  100.     @Basic(fetch = FetchType.LAZY)
  101.     private byte[] file;
  102. }
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