This is your query:
INSERT INTO '. self::TABLE . '_agrupamento_avaliacao (idSemana, idEntidade_agrupamento) VALUES(?, ?) ON DUPLICATE KEY UPDATE idEntidade_agrupamento = VALUES(idEntidade_agrupamento)');
The only unique index that you have on the table is the primary key on
id. This is auto-incremented, so it is not going to generate a duplicate.
Presumably, you want to declare
idSemana as being unique. Then the duplicate key can be caught. You were probably thinking that
index idSemana is sufficient for this purpose, but you really need