Advertisement
Guest User

Untitled

a guest
Feb 5th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. @Entity
  2. public class Usuario implements UserDetails {
  3. private static final long serialVersionUID = 1L;
  4.  
  5. @Id
  6. private String username;
  7.  
  8. private String password;
  9. private String nome;
  10.  
  11. @OneToMany(fetch=FetchType.EAGER)
  12. private List<Role> roles = new ArrayList<Role>();
  13.  
  14. ...
  15. }
  16.  
  17. @Entity
  18. public class Role implements GrantedAuthority {
  19. private static final long serialVersionUID = 1L;
  20.  
  21. @Id
  22. private String role;
  23. private String name;
  24.  
  25. ...
  26. }
  27.  
  28. Hibernate: create table Usuario (username varchar(255) not null, nome varchar(255), password varchar(255), primary key (username))
  29. Hibernate: create table Usuario_Role (Usuario_username varchar(255) not null, roles_role varchar(255) not null)
  30. Hibernate: alter table Usuario_Role add constraint UK_9ljdlf4fugq6jh14x7obwpi37 unique (roles_role)
  31. Hibernate: alter table Usuario_Role add constraint FKb32xr1fddmr4pxdxuj5u14f56 foreign key (roles_role) references Role (role)
  32. Hibernate: alter table Usuario_Role add constraint FKm7abqk7krlrd3bb61ecux2fnx foreign key (Usuario_username) references Usuario (username)
  33.  
  34. mysql> show tables;
  35. +-----------------+
  36. | Tables_in_kmcdb |
  37. +-----------------+
  38. | atendimento |
  39. | role |
  40. | usuario |
  41. | usuario_role |
  42. +-----------------+
  43. 4 rows in set (0.00 sec)
  44.  
  45. mysql> select * from role;
  46. +------------+---------------+
  47. | role | name |
  48. +------------+---------------+
  49. | ROLE_ADMIN | Administrador |
  50. | ROLE_SUP | Supervisor |
  51. | ROLE_TEC | Técnico |
  52. +------------+---------------+
  53. 3 rows in set (0.00 sec)
  54.  
  55. mysql> insert into usuario(username, nome, password) value('admin','admin','admin');
  56. Query OK, 1 row affected (0.03 sec)
  57.  
  58. mysql> insert into usuario(username, nome, password) value('fillipe','fillipe','fillipe');
  59. Query OK, 1 row affected (0.00 sec)
  60.  
  61. mysql> insert into usuario_role(usuario_username, roles_role) value('admin','ROLE_ADMIN');
  62. Query OK, 1 row affected (0.05 sec)
  63.  
  64. mysql> insert into usuario_role(usuario_username, roles_role) value('fillipe','ROLE_SUP');
  65. Query OK, 1 row affected (0.00 sec)
  66.  
  67. mysql> insert into usuario_role(usuario_username, roles_role) value('fillipe','ROLE_TEC');
  68. Query OK, 1 row affected (0.00 sec)
  69.  
  70. mysql> select * from usuario_role;
  71. +------------------+------------+
  72. | Usuario_username | roles_role |
  73. +------------------+------------+
  74. | admin | ROLE_ADMIN |
  75. | fillipe | ROLE_SUP |
  76. | fillipe | ROLE_TEC |
  77. +------------------+------------+
  78. 3 rows in set (0.00 sec)
  79.  
  80. mysql> insert into usuario_role(usuario_username, roles_role) value('fillipe','ROLE_ADMIN');
  81. ERROR 1062 (23000): Duplicate entry 'ROLE_ADMIN' for key 'UK_9ljdlf4fugq6jh14x7obwpi37'
  82. mysql> insert into usuario_role(usuario_username, roles_role) value('admin','ROLE_SUP');
  83. ERROR 1062 (23000): Duplicate entry 'ROLE_SUP' for key 'UK_9ljdlf4fugq6jh14x7obwpi37'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement