We are Borg
We are Borg

Reputation: 5313

HQL, PostgreSQL : Not in clause not working, syntax error at )

I am working on a Spring-MVC application, and we use Hibernate as the ORM tool. Currently, I am trying to search with a NOT in clause in Hibernate and providing a List<Integer> to it. I am getting the following error :

Error log :

org.postgresql.util.PSQLException: ERROR: syntax error at or near ")"
  Position: 2082
    org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2198)
    org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1927)
    org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
    org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:561)
    org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:419)
    org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:304)
    org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:96)
    org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:96)
    org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:82)
    org.hibernate.loader.Loader.getResultSet(Loader.java:2066)
    org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1863)
    org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1839)
    org.hibernate.loader.Loader.doQuery(Loader.java:910)
    org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:355)
    org.hibernate.loader.Loader.doList(Loader.java:2554)
    org.hibernate.loader.Loader.doList(Loader.java:2540)
    org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2370)
    org.hibernate.loader.Loader.list(Loader.java:2365)
    org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:497)
    org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:387)
    org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:236)
    org.hibernate.internal.SessionImpl.list(SessionImpl.java:1300)
    org.hibernate.internal.QueryImpl.list(QueryImpl.java:103)

HQL query :

 @Override
    public List<GroupNotes> searchForTextInGroup(long groupId, String text, List<Integer> canvasNotAllowedList) {
        Session session = this.sessionFactory.getCurrentSession();
        Query query = session.createQuery("from GroupNotes as gn where gn.groupId=:groupId and gn.canvasId not in (:canvasIdList) and gn.tags like :tag");
        query.setParameter("groupId", groupId);
        query.setParameter("tag", "%" + text + "%");
        query.setParameterList("canvasIdList",canvasNotAllowedList);
        return query.list();
    }

Any ideas what we are doing wrong? Thank you.

UPDATE

Debug output with query :

DEBUG: org.hibernate.SQL - select groupnotes0_.mnoteid as mnoteid1_25_, groupnotes0_.activeedit as activeed2_25_, groupnotes0_.canvas_id as canvas_i3_25_, groupnotes0_.collapse as collapse4_25_, groupnotes0_.copy_timestamp as copy_tim5_25_, groupnotes0_.creatorid as creatori6_25_, groupnotes0_.disabled_sort_id as disabled7_25_, groupnotes0_.end_is_milestone as end_is_m8_25_, groupnotes0_.erledigt_timestamp as erledigt9_25_, groupnotes0_.excel_data as excel_d10_25_, groupnotes0_.finished as finishe11_25_, groupnotes0_.gannt as gannt12_25_, groupnotes0_.ganntorder as ganntor13_25_, groupnotes0_.gantt_duration as gantt_d14_25_, groupnotes0_.gantt_status as gantt_s15_25_, groupnotes0_.group_id as group_i16_25_, groupnotes0_.level as level17_25_, groupnotes0_.mnotecolor as mnoteco18_25_, groupnotes0_.mnoteorder as mnoteor19_25_, groupnotes0_.mnoteheadline as mnotehe20_25_, groupnotes0_.mnotetext as mnotete21_25_, groupnotes0_.timestamp as timesta22_25_, groupnotes0_.notecreatoremail as notecre23_25_, groupnotes0_.notedate as notedat24_25_, groupnotes0_.notedisabled as notedis25_25_, groupnotes0_.noteinactive as noteina26_25_, groupnotes0_.note_milestone as note_mi27_25_, groupnotes0_.notenumber as notenum28_25_, groupnotes0_.notetarget as notetar29_25_, groupnotes0_.msectionid as msectio46_25_, groupnotes0_.pad_id as pad_id30_25_, groupnotes0_.person_who_zugweised as person_31_25_, groupnotes0_.prefix as prefix32_25_, groupnotes0_.preview_text as preview33_25_, groupnotes0_.privatenoteflag as private34_25_, groupnotes0_.privatenoteuser as private35_25_, groupnotes0_.processing as process36_25_, groupnotes0_.startDate as startDa37_25_, groupnotes0_.start_is_milestone as start_i38_25_, groupnotes0_.tags as tags39_25_, groupnotes0_.target_time as target_40_25_, groupnotes0_.task_relations as task_re41_25_, groupnotes0_.uploader as uploade42_25_, groupnotes0_.urgent as urgent43_25_, groupnotes0_.zugwisenpersonid as zugwise44_25_, groupnotes0_.zugwisen_person_timestamp as zugwise45_25_ from groupnotes groupnotes0_ where groupnotes0_.group_id=? and (groupnotes0_.canvas_id not in  ()) and (groupnotes0_.tags like ?)
DEBUG: org.hibernate.engine.jdbc.spi.SqlExceptionHelper - could not extract ResultSet [n/a]
org.postgresql.util.PSQLException: ERROR: syntax error at or near ")"
  Position: 2082
    at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2198)
    at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1927)
    at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:561)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:419)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:304)
    at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:96)
    at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:96)

Upvotes: 2

Views: 886

Answers (1)

itsccn
itsccn

Reputation: 81

query.setParameterList("canvasIdList",canvasNotAllowedList);

Maybe canvasNotAllowedList is empty.

Upvotes: 4

Related Questions