I've been trying variations on this, but I can't seem to get Ebean to recognize the constraint.
@ElementCollection
@CollectionTable(schema = "participants", joinColumns = @JoinColumn(name = "role_id"), uniqueConstraints = {
//The presence of actual column names in this line is an unfortunate consequence of eBean and JPA annotations
@UniqueConstraint(columnNames = {"integration_tag", "role_id"})
})
private final List<DefaultAccount> defaultIntegrationAccounts = new ArrayList<>();
For reference, here's DefaultAccount:
@Embeddable
public class DefaultAccount {
@NotNull
private final String integrationTag;
@NotNull
@ManyToOne
private Account account;
DefaultAccount(String integrationTag, Account account) {
this.integrationTag = integrationTag;
this.account = account;
}
public String getIntegrationTag() {
return integrationTag;
}
public Account getAccount() {
return account;
}
public void setAccount(Account account) {
this.account = account;
}
}
Oddly enough, everything works well if DefaultAccount is made to be an entity rather than an embeddable, but this just goes against the domain modelling and I'd really rather not go down that route unless I absolutely have to...
In the limitations section of the Ebean documentation linked here, it says
And you have identified that changing the
DefaultAccountto an entity resolves the problem, so I think you have already identified the solution.