Caused by: org.postgresql.util.psqlexception: error: operator does not exist: character varying = bytea

Hey, i am working on Create an Event Listener that listens to patient creation by mherman22 · Pull Request #1065 · I-TECH-UW/OpenELIS-Global-2 · GitHub and i have had to do alot of changes especially with how beans are being created with an aim of making the existing tests pass and get the app up and running for me to test my changes.

I am getting an error in the terminal when i start the app, find the logs at Ubuntu Pastebin. I have written a test case and it passes but for some reason i am yet to establish, the enum value is sent as bytea and not as a string as it should.

I have even gone ahead to use type safe enabled by the jpa criteria api as seen below but all in vain:

  public NotificationPayloadTemplate getSystemDefaultPayloadTemplateForType(NotificationPayloadType type) {
    List<NotificationPayloadTemplate> data;
    try {
      CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
      CriteriaQuery<NotificationPayloadTemplate> criteriaQuery = criteriaBuilder.createQuery(NotificationPayloadTemplate.class);
      Root<NotificationPayloadTemplate> root = criteriaQuery.from(NotificationPayloadTemplate.class);
      criteriaQuery.where(criteriaBuilder.equal(root.get("type"), type));
      criteriaQuery.orderBy(criteriaBuilder.asc(root.get("id")));
      TypedQuery<NotificationPayloadTemplate> query = entityManager.createQuery(criteriaQuery);
      query.setMaxResults(1);
      data = query.getResultList();
    } catch (RuntimeException e) {
      LogEvent.logError(e);
      throw new LIMSRuntimeException("Error in getSystemDefaultPayloadTemplateForType", e);
    }

    return data.isEmpty() ? null : data.get(0);
  }

cc: @Moses_Mutesasira @reagan @sharif @everyone

Caused by: org.postgresql.util.PSQLException: ERROR: operator does not exist: character varying = bytea
openelisglobal-webapp  |   Hint: No operator matches the given name and argument types. You might need to add explicit type casts.

Its usually caused by hibernate failing to determine the arg type in a Hibernate query

Its most probably caused by this change

query.setParameter("type", type.name()); but you changed it to query.setParameter("type", type);

In the DB type is saved as a String , so you should convert the ENUM to a string value when querying with hibernate

3 Likes