java - How to map a custom table returned from a stored procedure -
i'm using postgresql , hibernate, have stored procedure returns custom table, how map java bean custom table? wrote java class not sure if should use annotations.
my sp:
create or replace function reporte_gas_federal() returns table(tipologia text, "número de clientes" bigint, "saturación de mercado" text, "distribución clientes nivel federal" text) $body$ cruce_tipo_gas (select wise_ageb.id_ageb, wise_ageb.cvgeo_ageb, wise_ageb.tipo, nombre,tipologias_ageb.clave, wise_ageb_geom.geom wise_ageb join wise_ageb_geom on wise_ageb.id_ageb = wise_ageb_geom.id_ageb join tipologias_ageb on tipologias_ageb.id_ageb = wise_ageb.id_ageb join tipologias on tipologias_ageb.clave = tipologias.clave), conteo_parcial (select distinct nombre, count(nombre) conteo gasnatural_clientes inner join cruce_tipo_gas on st_intersects(cruce_tipo_gas.geom, gasnatural_clientes.geom) group by( nombre ) order nombre asc), cruce_manzana (--obtiene cruce de las manzanas para pobtnener datos de pob select id_manzana, clave wise_manzana join cruce_tipo_gas using(id_ageb)), pob_tipologia --poblacio total x tipologia (select sum(cast(pobtot int))as poblacion, clave wise_manzana_poblacion join cruce_manzana using (id_manzana) group clave), conteo_total_pob --poblacion total en la region (select sum(poblacion) pobtot pob_tipologia), conteo_total (select sum(conteo) total conteo_parcial) select nombre "tipología",conteo "número de clientes", concat( round(( ( conteo / total ) * 100 ),4),'%') "saturación de mercado", concat(round(( cast(conteo decimal) / pobtot ) * 100, 4), '%') "distribución clientes nivel federal" conteo_parcial cross join conteo_total cross join conteo_total_pob order conteo desc; $body$ language sql volatile cost 100 rows 1000; alter function reporte_gas_federal() owner postgres;
you can use rowmapper if have jdbctemplate example:
public customresult getcustomresult(){ final string sql = "call reporte_gas_federal"; final customresult customresult = (customresult) jdbctemplate.queryforobject(sql, new customresultrowmapper()); return customresult; } public class customresultrowmapper implements rowmapper { public object maprow(resultset rs, int rownum) throws sqlexception { customresult customresult = new customresult(); customresult.set(... ... return customresult; } } otherwise can use resultransformer example:
customresult customresult = (customresult)session.createsqlquery("call reporte_gas_federal") .setresulttransformer(new basictransformeradapter() { private static final long serialversionuid = 1l; @override public object transformtuple(object[] tuple, string[] aliases){ final customresult customresult = new customresult(); customresult customresult = new customresult(); customresult.set(... ... return customresult; } }).uniqueresult(); or .setresulttransformer(transformers.aliastobean(customresult.class)) instead of custom transformer.
Comments
Post a Comment