Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Entity
- @Table(name = "user")
- public class User {
- @OneToMany(mappedBy = "user", cascade = CascadeType.ALL)
- @MapKeyColumn(name = "AppId", insertable = false, updatable = false)
- @MapKeyEnumerated(EnumType.STRING)
- private Map<ApplicationsEnum, AbstractAccount> accounts;
- }
- @Entity
- @Inheritance(strategy = InheritanceType.JOINED)
- @Table(name = "accounts")
- public abstract class Account {
- @EmbeddedId
- private AccountID id;
- @ManyToOne
- @MapsId("id")
- @JoinColumn(name = "UserId", referencedColumnName = "Id")
- private Utilisateur user;
- }
- @Embeddable
- public class AccountID implements Serializable {
- @Column(name = "UserId")
- private Long id;
- @Column(name = "AppId")
- @Enumerated(EnumType.STRING)
- private ApplicationsEnum AppId;
- }
- "select distinct user
- from User user
- left join fetch user.accounts accounts on (TYPE(accounts) = AccountA or TYPE(accounts) = AccountB)"
Add Comment
Please, Sign In to add comment