This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jan 28th, 2013  |  syntax: None  |  size: 1.20 KB  |  views: 22  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. principal_id    permission    target
  2. 12312313        PERM1         1000
  3. 12312313        PERM2         1000
  4. 12312313        PERM2         1002
  5.        
  6. @Entity
  7. ...
  8. public class Principal {
  9.     @Id
  10.     private long principalId;
  11.  
  12.     ...
  13.  
  14.     private Map<String, List<Long>> permissionMap;
  15.  
  16. }
  17.        
  18. @Entity
  19. ...
  20. public class Principal {
  21.  
  22.     @Id
  23.     private long principalId;
  24.     /** Other properties **/
  25.     @OneToMany
  26.     private Set<Permission> permissions;
  27. ....
  28. }
  29.  
  30. @Entity
  31. @IdClass(PermissionId.class)
  32. public class Permission {
  33.     @Id
  34.     private String permission;
  35.     @Id
  36.     private Long target
  37.  
  38.     public static class PermissionId implements Serializable {
  39.         private String permission;
  40.         private Long target;
  41.         /** setters/getters hashcode and equals goes here **/
  42.     }
  43. }
  44.        
  45. @Embeddable
  46. public class Permission {
  47.     private String permission;
  48.     private int target;
  49. }
  50.  
  51. @ElementCollection
  52. @CollectionTable(name="foo", joinColumns = @JoinColumn(name = "principal_id"))
  53. private Set<Permission> permissions;
  54.        
  55. @ElementCollection
  56. @CollectionTable(name="foo", joinColumns = @JoinColumn(name = "principal_id"))
  57. @MapKeyColumn(name="permission")
  58. @Column(name="target")
  59. private Map<String, Integer> permissions;
clone this paste RAW Paste Data