java - JPA query works with number but not with Integer variable -




i have written code retrieving list of object postgres db. query gives me correct result if write value of id_utente_pres (for example 68) in criteria. if use integer variable called "id" result set empty.

code retreive correct result set:

public list<prenotazione> getprenotazioni(integer id) throws remoteexception {     session session;     session = sessionfactory.opensession();      criteriabuilder builder = session.getcriteriabuilder();     criteriaquery<prenotazione> criteria = builder.createquery(prenotazione.class);     root<prenotazione> prenotazionefind = criteria.from(prenotazione.class);     criteria.select(prenotazionefind);      parameterexpression<integer> p = builder.parameter(integer.class);     criteria.where(builder.equal(prenotazionefind.get("id_utente_pren"), 68));     list<prenotazione> prenotazioniutente = session.createquery(criteria).getresultlist();     session.close();     return prenotazioniutente; } 

generated sql: hibernate: select prenotazio0_.id_prenotazione id_preno1_6_, prenotazio0_.dataprenotazione datapren2_6_, prenotazio0_.id_libro id_libro3_6_, prenotazio0_.id_utente_pren id_utent4_6_ table_prenotazioni prenotazio0_ prenotazio0_.id_utente_pren=68

code returns empty result set:

public list<prenotazione> getprenotazioni(integer id) throws remoteexception {     session session;     session = sessionfactory.opensession();      criteriabuilder builder = session.getcriteriabuilder();     criteriaquery<prenotazione> criteria = builder.createquery(prenotazione.class);     root<prenotazione> prenotazionefind = criteria.from(prenotazione.class);     criteria.select(prenotazionefind);      parameterexpression<integer> p = builder.parameter(integer.class);     criteria.where(builder.equal(prenotazionefind.get("id_utente_pren"), id));     list<prenotazione> prenotazioniutente = session.createquery(criteria).getresultlist();     session.close();     return prenotazioniutente; } 

generated sql: hibernate: select prenotazio0_.id_prenotazione id_preno1_6_, prenotazio0_.dataprenotazione datapren2_6_, prenotazio0_.id_libro id_libro3_6_, prenotazio0_.id_utente_pren id_utent4_6_ table_prenotazioni prenotazio0_ prenotazio0_.id_utente_pren=?





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -