The SecondaryTable works only for tables whose rows are in a
one-to-one relationship. In your case, there is a one-to-many association, so the mapping is wrong.
1. You need to map Repository and RepositoryCredentialAssn as individual entities
2. In RepositoryCredentialAssn, you need to have:
Code:
@ManyToOne
@JoinColumnsOrFormulas(
{
@JoinColumnOrFormula(column=@JoinColumn(name="repository_id", referencedColumnName="id")),
@JoinColumnOrFormula(formula=@JoinFormula(value="true", referencedColumnName="is_default"))
})
private Repository repository;
3. Then, in Repository you have the bidirectional one-to-many side:
Code:
@OneToMany(mappedBy = "repository", cascade = CascadeType.ALL, orphanRemoval = true)
private List<RepositoryCredentialAssn> credentials = new ArrayList<>();
So you can access the RepositoryCredentialAssn like this:
Code:
Repository repository - entotuManager.find(Repository.class, repositoryId);
List<RepositoryCredentialAssn> credentials = repository.getCredentials();