Search code examples
javajpaentitymanager

JPA Query to select from DB


i have this method:

public List<String> getTipoConsensoRichiesto(String tipologiaProdotto) {
    return entityManager.createNativeQuery("Select TIPO_CONSENSO_RICHIESTO from  PRIVACY_CONFIGURAZIONE WHERE TIPOLOGIA_PRODOTTO = :tipologiaProdotto ")
        .setParameter("tipologiaProdotto",tipologiaProdotto)
        .getResultList();
}

when i execute the query i have the following problem:

Internal Exception: java.sql.SQLException: Parametro IN o OUT mancante nell'indice:: 1 Error Code: 17041 Call: Select TIPO_CONSENSO_RICHIESTO from PRIVACY_CONFIGURAZIONE WHERE TIPOLOGIA_PRODOTTO = :tipologiaProdotto Query: DataReadQuery(sql="Select TIPO_CONSENSO_RICHIESTO from PRIVACY_CONFIGURAZIONE WHERE TIPOLOGIA_PRODOTTO = :tipologiaProdotto ")

How i can solve? Thank you


Solution

  • Try using:

    return entityManager.createNativeQuery("Select TIPO_CONSENSO_RICHIESTO from PRIVACY_CONFIGURAZIONE WHERE TIPOLOGIA_PRODOTTO = ?1 ").setParameter(1,tipologiaProdotto).getResultList();