Ho riscritto il database precedente che mi piaceva poco ma senza fare grosse modifiche e tutte le query, dai test, sembrano funzionare, fatta eccezione per quella che tenta di inserire un nuovo utente nel DB.
Ottengo questo errore:
org.springframework.dao.InvalidDataAccessApiUsageException: The getKey method should only be used when a single key is returned. The current key entry contains multiple keys: [{id=4, nome=prova, password=password, abilitato=false}]
La query è questa:
    public Utente crea(final Utente utente) {
        final String sql = "INSERT INTO utenti (nome, password, abilitato) VALUES (?, ?, ?);";
        KeyHolder holder = new GeneratedKeyHolder();
        jdbcTemplate.update(new PreparedStatementCreator() {
            @Override
            public PreparedStatement createPreparedStatement(Connection connection)
                    throws SQLException {
                PreparedStatement ps = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
                ps.setString(1, utente.getNome());
                ps.setString(2, utente.getPassword());
                ps.setBoolean(3, utente.getAbilitato());
                return ps;
            }
        }, holder);
        Long nuovoIdUtente = holder.getKey().longValue();
        utente.setId(nuovoIdUtente);
        return utente;
    }
Il test questo:
	@Test
	public void creaUnUtente() {
		Utente utente = new Utente(0L, "prova", "password", false);
		Utente utenteSalvato = utenteRepository.crea(utente);
		Utente nuovoUtente = utenteRepository.trovaUtente(utenteSalvato.getId());
		assertEquals("prova", nuovoUtente.getNome());
		assertEquals("password", nuovoUtente.getPassword());
	}
Ecco il database:
schema.sql
CREATE TABLE utenti (
    id BIGSERIAL PRIMARY KEY,
    nome VARCHAR(100) NOT NULL,
    password VARCHAR(255) NOT NULL,
    abilitato BOOLEAN NOT NULL,
    UNIQUE (nome)
);
CREATE TABLE ruoli (
    id SERIAL PRIMARY KEY,
    ruolo VARCHAR(100) NOT NULL,
    UNIQUE (ruolo)
);
CREATE TABLE id_utenti_id_ruoli (
    id BIGSERIAL PRIMARY KEY,
    id_utente BIGSERIAL NOT NULL,
    id_ruolo SERIAL NOT NULL,
    FOREIGN KEY (id_utente) REFERENCES utenti (id) ON DELETE CASCADE,
    FOREIGN KEY (id_ruolo) REFERENCES ruoli (id) ON DELETE CASCADE,
    UNIQUE (id_utente, id_ruolo)
);
CREATE TABLE persistent_logins (
    username VARCHAR(100) NOT NULL,
    series VARCHAR(64) PRIMARY KEY,
    token VARCHAR(64) NOT NULL,
    last_used TIMESTAMP NOT NULL
);
data.sql
BEGIN TRANSACTION;
INSERT INTO utenti (nome, password, abilitato)
VALUES ('pro1', '$2a$10$PrI5Gk9L.tSZiW9FXhTS8O8Mz9E97k2FZbFvGFFaSsiTUIl.TCrFu', true);
INSERT INTO utenti (nome, password, abilitato)
VALUES ('amm1', '$2a$10$PrI5Gk9L.tSZiW9FXhTS8O8Mz9E97k2FZbFvGFFaSsiTUIl.TCrFu', true);
INSERT INTO ruoli (ruolo) VALUES ('proprietario');
INSERT INTO ruoli (ruolo) VALUES ('amministratore');
INSERT INTO ruoli (ruolo) VALUES ('gestore');
INSERT INTO ruoli (ruolo) VALUES ('organizzatore');
INSERT INTO ruoli (ruolo) VALUES ('utente_semplice');
INSERT INTO id_utenti_id_ruoli (id_utente, id_ruolo) VALUES (1, 1);
INSERT INTO id_utenti_id_ruoli (id_utente, id_ruolo) VALUES (1, 2);
INSERT INTO id_utenti_id_ruoli (id_utente, id_ruolo) VALUES (1, 3);
INSERT INTO id_utenti_id_ruoli (id_utente, id_ruolo) VALUES (1, 4);
INSERT INTO id_utenti_id_ruoli (id_utente, id_ruolo) VALUES (2, 2);
INSERT INTO id_utenti_id_ruoli (id_utente, id_ruolo) VALUES (2, 3);
INSERT INTO id_utenti_id_ruoli (id_utente, id_ruolo) VALUES (2, 4);
COMMIT;