Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

285
Vistas
Returning Postgresql json in Entity Manager

I'm attempting to use ENTITY MANAGER to return a POSTGRESQL 9.6 Stored Procedure/Function JSON result. THIS RETURNS 1 RECORD ONLY.

**POSTGRESQL TABLES**

TABLE: **customer**
 [enter image description here][1]

TABLE: **names**
 [enter image description here][2]

TABLE: **address**
 [enter image description here][3]

**POSTGRESQL STORED PROCEDURE**

CREATE OR REPLACE FUNCTION  jsp_member_main(
    IN cid numeric,
    OUT t json)
    RETURNS json
    LANGUAGE 'sql'
    COST 100.0
    VOLATILE 
AS $function$

select json_agg(t)
from (SELECT 
c.id customer_id,
n.first_name,
n.last_name,
a.street1,
a.city,
a.state,
a.postal_code

FROM customer c 
LEFT OUTER JOIN names n ON (c.name_id = n.id)
LEFT OUTER JOIN address a ON (c.id = a.customer_id)
WHERE c.id=cid
) t;
$function$
 
**POSTGRESQL STORED PROCEDURE QUERY**

select jsp_member_main(99964);

**RETURNS VIA SQL**

[{"customer_id":99964,"first_name":"JOHN","last_name":"SMITH","street1":"123 W. MAIN ST.","city":"SPINDALE","state":"MD","postal_code":"21791"}]

So far, so good. Now I try to use ENTITY MANAGER to return results:

    @GET
    @Path("SP Member Main")
    @Produces({"application/xml", "application/json"})
    public JSONObject memberMain() throws JSONException {
        EntityManager em =  getEntityManager();
        StoredProcedureQuery storedProcedure = em.createStoredProcedureQuery("jsp_member_main");
        storedProcedure.registerStoredProcedureParameter("cid", Integer.class, ParameterMode.IN);
        storedProcedure.registerStoredProcedureParameter("t", JSONObject.class, ParameterMode.OUT);
        storedProcedure.setParameter("cid", 99964);
        storedProcedure.execute();
        JSONObject retval = (JSONObject) storedProcedure.getOutputParameterValue("t");
        return retval;
    }

No matter what return (OUT) type class I try, I get the following error:

***javax.ejb.EJBException
root cause
javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: org.postgresql.util.PSQLException: A CallableStatement function was executed and the out parameter 1 was of type java.sql.Types=1111 however type java.sql.Types=12 was registered.
Error Code: 0
Call: {?= CALL ross.jsp_member_main(?)}
    bind => [2 parameters bound]
Query: ResultSetMappingQuery()***

I've tried as String class, returning toString, JSONArray cobverting JSONObject to JSONArray, java OBJECT, etc. Nothing works.

Is there a way through ENTITY MANAGER to return json from a Postgresql stored procedure/function? Many thanks for your consideration.

over 4 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda