I encountered an error as per title at query.getResultList()
; on JsonbHibernateExampleApplicationTests
class file when running native query to return a json object.
It has no issue returning of non json
type of column.
Kindly assist and do let me know if there is a need for more information.
Below is the source code
public class JsonbHibernateExampleApplicationTests {
@Autowired
private PersonRepository repository;
@Autowired
private ApplicationContext appContext;
@Test
public void contextLoads() {
EntityManagerFactory entityManagerFactory = (EntityManagerFactory) appContext
.getBean("entityManagerFactory");
EntityManager entityManager = entityManagerFactory.createEntityManager();
String sql = "select additional_data from person";
javax.persistence.Query query = entityManager.createNativeQuery(sql);
query.getResultList();
//List<JsonDataUserType> list = (List<JsonDataUserType>) query.getResultList();
/* System.out.println("list:" + list);
for (JsonDataUserType json: list)
{
System.out.println("json:" + json);
}*/
//List<Object[]> objects = query.getResultList();
//System.out.println("result:"+ objects);
}
}
I specified the additional_data column as customized json type in the entity
@Type(type = "JsonDataUserType")
private Map<String, String> additionalData;
I can't paste all the source code here and you can check out the full source code at http://vojtechruzicka.com/postgresqls-jsonb-type-mapping-using-hibernate/
I just modified the original source as URL above to run a native SQL query.
Many Thanks,