hibernate-native-query

how to get list of long values in hibernate from the table while casting from bigint to long

随声附和 提交于 2019-12-12 19:19:44
问题 I get the following exception when using the getEvents method: org.hibernate.MappingException: Unknown entity: java.lang.Long public List<Long> getEvents(Person person) { String q = "select new java.lang.Long(te.event_id) " + "from teachers_event te" + "where te.teachers_id = :personId "; Query query = entityManager.createNativeQuery(q, Long.class); query.setParameter("personId", person.getId()); return (List<Long>) query.getResultList(); } The teachers_event table in database connects the id

Hibernate createNativeQuery returning Proxy object for Clob

こ雲淡風輕ζ 提交于 2019-12-12 15:51:15
问题 I am forced into a situation where i am using hibernate createNativeQuery to return a List of Objects arrays. One of the (many) columns from which my query returns values is a CLOB. The Object which is returned is com.sun.Proxy object. I have seen a question here where getClass().getInterfaces() was used to identify that it is a WrappedClob being returned. However given that I now have this proxy object in my Java code, how do I convert it into something useful ... like a String? 回答1: The

JPA and JSON operator native query

不羁的心 提交于 2019-12-09 18:13:42
问题 I'm trying to make this query work in JPA: SELECT * FROM contrat WHERE contrat_json @> '{"nom" :"hever"}'; It works perfectly with postgresql but when I integrate it with JPA, I get the following error: Parameter with that position [1] did not exist My code: @Transactional @Query(nativeQuery = true,value = "select p from Contrat p where contrat_json @> '{\"nom\":\":nom\"}'") public List<Contrat> findByNomRestrict(@Param("nom") String nom); I think it does not recognize @> despite native query