Facebook
From SSikora, 1 Year ago, written in Java.
Embed
Download Paste or View Raw
Hits: 97
  1. //////////////////////////////Tabela Account
  2.  
  3. //....
  4.  
  5.     @ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.PERSIST)
  6.     @JoinTable(name = "ACCOUNT_ROLE",
  7.             joinColumns = @JoinColumn(name = "ID_ACCOUNT", unique = false, nullable = false),
  8.             inverseJoinColumns = @JoinColumn(name = "ID_ROLE", unique = false, nullable = false))
  9.     private Set<Role> roles;
  10.    
  11.    ..../
  12.    
  13. //////////////////////////////Tabela Role
  14.  
  15. @Data
  16. @Table(name = "ROLE", uniqueConstraints = {
  17.         @UniqueConstraint(columnNames = "ID_ROLE"),
  18.         @UniqueConstraint(columnNames = "NAME")
  19. })
  20. public class Role implements Serializable {
  21.  
  22.     private static final long serialVersionUID = 1L;
  23.  
  24.     @Id
  25.     @GeneratedValue(strategy = GenerationType.IDENTITY)
  26.     @Column(name = "ID_ROLE")
  27.     private Integer idRole;
  28.  
  29.     @Column(name = "NAME")
  30.     private String name;
  31. }
  32.  
  33.  
  34.  
  35. //////////////////////////////AccountRepository
  36.  
  37.  
  38. public interface AccountRepository extends JpaRepository<Account, Integer>, JpaSpecificationExecutor<Account> {
  39.  
  40.     @Query(value = "SELECT * FROM account u where u.is_active = :IS_ACTIVE"
  41.             , nativeQuery = true)
  42.     List<Account> findAllWhereUserIsActive(@Param("IS_ACTIVE") Boolean is_active);
  43.  
  44.     //..
  45.    
  46.     ..//
  47. }
  48.