ManyToOne/Many Only fetches first matching row when using Join Table?

Hello. I have 3 tables.


Each contracth has a user_id (not the PK), a user can have several contracts. A user can be referred by an affiliate in which case their relationship would be added to the Affiliate_User join table.

I am trying to get out all Contracts which belong to users who have been referred by a specific affiliate. It works for getting the contracts, but it seems to only get the first contract for every user.

Will be eternally grateful for anyone who can help out. Here is what the code looks like currently but I have tried to implement it in a million different ways now and it either doesn’t work or it doesn’t fetch all of the contracts.

Query to fetch:
Affiliate affiliate = (Affiliate) em.createQuery("SELECT a from Affiliate a where a.affiliateID=:value1")
                .setParameter("value1", affiliateID)

In Affiliate Model
    @ManyToMany(fetch = FetchType.EAGER)
        name = "Affiliate_User",
        joinColumns = { @JoinColumn(name = "affiliate_user_id") },
        inverseJoinColumns = { @JoinColumn(name = "referred_user_id", referencedColumnName = "user_id")})
    private Set<Contract> referredContracts = new HashSet<>();

In Contract Model
    @ManyToMany(fetch = FetchType.LAZY)
        name = "Affiliate_User",
        joinColumns = { @JoinColumn(name = "referred_user_id") },
        inverseJoinColumns = { @JoinColumn(name = "affiliate_user_id", referencedColumnName = "user_id")})
    private List<Affiliate> affiliate;

Have you tried using the following in the Contract model yet?

@ManyToMany(fetch = FetchType.LAZY, mappedBy = "referredContracts")
private List<Affiliate> affiliate;