Guest User

Untitled

a guest
Oct 26th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. @Entity
  2. @Table(name = "user")
  3. public class User {
  4.  
  5. @OneToMany(mappedBy = "user", cascade = CascadeType.ALL)
  6. @MapKeyColumn(name = "AppId", insertable = false, updatable = false)
  7. @MapKeyEnumerated(EnumType.STRING)
  8. private Map<ApplicationsEnum, AbstractAccount> accounts;
  9.  
  10. }
  11.  
  12. @Entity
  13. @Inheritance(strategy = InheritanceType.JOINED)
  14. @Table(name = "accounts")
  15. public abstract class Account {
  16.  
  17. @EmbeddedId
  18. private AccountID id;
  19.  
  20. @ManyToOne
  21. @MapsId("id")
  22. @JoinColumn(name = "UserId", referencedColumnName = "Id")
  23. private Utilisateur user;
  24. }
  25.  
  26. @Embeddable
  27. public class AccountID implements Serializable {
  28.  
  29. @Column(name = "UserId")
  30. private Long id;
  31.  
  32. @Column(name = "AppId")
  33. @Enumerated(EnumType.STRING)
  34. private ApplicationsEnum AppId;
  35. }
  36.  
  37. "select distinct user
  38. from User user
  39. left join fetch user.accounts accounts on (TYPE(accounts) = AccountA or TYPE(accounts) = AccountB)"
Add Comment
Please, Sign In to add comment