i used a native query to call a function in my postgresql database, code is like this:
String query = "select details,rec_xml[1] from f_get_reccomendations(\'/ma:recommendations/ma:recommendation/name/text()\') ORDER BY id DESC LIMIT 1;";
Query q = em.createNativeQuery(query);
return q.getResultList();
the function defined as:
CREATE OR REPLACE FUNCTION f_get_reccomendations (
IN xpath varchar(128),
OUT id int,
OUT recs_num int,
OUT details varchar(25),
OUT d_stamp timestamp,
OUT rec_xml xml[]
) RETURNS SETOF RECORD AS
$$
select id, recs_num, details, d_stamp, xpath($1, recs,
array [
array['xs','http://www.w3.org/2001/XMLSchema'],
array['ma','http://schemas.medio.com/analytics/1.0']
]
) from recommendations;
$$
LANGUAGE SQL;
when ran from the psql, it worked, but when i run in the code, it threw me error:
No Dialect mapping for JDBC type: 2009
my guess is the rec_xml is defined as xml[] type that hibernate could not understand? how can i fix it? Thanks
First: Are you sure it’s the array of XML, not the xml type its self, that’s the issue? I’ve found Hibernate’s support for Pg’s XML type to be somewhere between poor and nonexistent.
If it proves to be the array: Try expanding the array of xml into a set, so you return the cross join of `recs’ and the rest of the results. This will require filtering on the client side to de-duplicate results.
Alternately, you could write a dialect type mapping for xml[] in Hibernate, or cast the xml to text so you return text[].