I'm trying to have the result of a query returned to me as a JSON string in java.
I have tried using both HQL and setting up a native SQL query, but it seems i'm required to use the UUID type, which i do not need because none of the fields are JSON. I have queried the database with a similar query and obtained results compatible with what i need
// the three lists in input are always the same length (controlled elsewhere)
public static String directQuery(List<String> vars, List<String> criteri, List<String> param){
Session session = HibernateUtility.getSessionFactory().openSession();
session.beginTransaction();
String query="";
String json="";
if(!GenericUtil.isNullOrBlank(vars)&&!GenericUtil.isNullOrBlank(criteri)&&!GenericUtil.isNullOrBlank(param)){
query="SELECT CAST(json_agg(results) as TEXT) FROM public.results WHERE ";
for(int i=0;i<vars.size();i++){
query=query+""+vars.get(i)+" "+criteri.get(i)+" "+param.get(i)+" AND ";
}
query=query.substring(0, query.length()-5);
}
json= (String) session.createSQLQuery(query).uniqueResult();
session.getTransaction().commit();
session.close();
return json;
}
I expect a JSONArray with numerous elements, but i have yet to see any output, but recieve this error
org.hibernate.MappingException: No Dialect mapping for JDBC type: 1111
How can this be solved? Thank you all for you time.
Edit: Changed the code to its most updated form