Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Error calling PostgreSQL stored procedure
Error calling PostgreSQL stored procedure [message #1859119] Fri, 12 May 2023 10:47 Go to next message
Marco Ferretti is currently offline Marco FerrettiFriend
Messages: 2
Registered: May 2023
Junior Member
Hi,
I am trying to debug an issue when using StoredProcedureQuery on a PostgreSQL database.
Say you have a sored procedure defined as follow:
CREATE OR REPLACE PROCEDURE public.testproc(IN anint bigint, IN astring character varying)
 LANGUAGE plpgsql
AS $procedure$
begin 
	raise notice 'you called testproc !';
end; $procedure$
;


and a jdbc url
jdbc:postgresql://database:5432/postgres?escapeSyntaxCallMode=callIfNoReturn


Using plain jdbc simply works:
            Connection conn = DriverManager.getConnection(url, props);
            CallableStatement s = conn.prepareCall("{call testproc(?, ?)}");
            s.setInt(1, 2984);
            s.setString(2, "CSLMF14");

            s.execute();


while JPA StoredProcedureQuery keeps on calling the procedure with SELECT statement instead of CALL :
        StoredProcedureQuery query = em.createStoredProcedureQuery("testproc")
                .registerStoredProcedureParameter(1, Long.class, ParameterMode.IN)
                .registerStoredProcedureParameter(2, String.class, ParameterMode.IN).setParameter(1, 2984)
                .setParameter(2, "CSLMF14");

        query.executeUpdate();

here's the relevant stacktrace:
Caused by: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.7.11.v20220804-52dea2a3c0): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: org.postgresql.util.PSQLException: ERROR: testproc(integer, character varying) is a procedure
  Hint: To call a procedure, use CALL.
  Position: 15
Error Code: 0
Call: SELECT * FROM testproc(?, ?)
bind => [2 parameters bound]


If I remove the connection parameter "escapeSyntaxCallMode" then I get the same error on plain jdbc too.

here's the persistence.xml I am using :
    <persistence-unit name="manualPU" transaction-type="RESOURCE_LOCAL">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <properties>
            <property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver" />
            <property name="javax.persistence.jdbc.url" value="jdbc:postgresql://database:5432/postgres?escapeSyntaxCallMode=callIfNoReturn" />
            <property name="javax.persistence.jdbc.user" value="myuser" />
            <property name="javax.persistence.jdbc.password" value="mypass" />
        </properties>
    </persistence-unit>


Am I missing something in the configuration ? It really looks like the driver isn't properly loaded or the connection url is overridden.

TIA
Re: Error calling PostgreSQL stored procedure [message #1859144 is a reply to message #1859119] Mon, 15 May 2023 08:29 Go to previous messageGo to next message
Marco Ferretti is currently offline Marco FerrettiFriend
Messages: 2
Registered: May 2023
Junior Member
Some more hints:
I have been debugging and I see that the value of
statement.query


being executed in
DatabaseAccessor.execute(DatabaseCall call, Statement statement, AbstractSession session)


is actually
SELECT * FROM TESTPROC(?, ?)

[Updated on: Mon, 15 May 2023 08:30]

Report message to a moderator

Re: Error calling PostgreSQL stored procedure [message #1859203 is a reply to message #1859144] Fri, 19 May 2023 00:49 Go to previous message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 60
Registered: December 2021
Member
Postgresql docs (https://jdbc.postgresql.org/documentation/callproc/ ) show that the escapeSyntaxCallMode parameter should default to 'select' if undefined, and that this behavior is still supported for functions and procedures. The callIfNoReturn seems to force stored procedures to use the { call(?,?)} format you are using with JDBC, while EclipseLink code (https://github.com/chenjiafan/eclipselink/blob/a1a6cfa35417931430bf2f4e3220d9ed72a2d6c2/org/eclipse/persistence/platform/database/PostgreSQLPlatform.java#L464 ) is using the older 'select' format "SELECT * FROM call(?, ?)" for them.

Try removing the escapeSyntaxCallMode=callIfNoReturn driver options and see if that works. If you must use it, you'll have to write your own DatabasePlatform class to extend PostgreSQLPlatform and override the stored proc string used to be what you need.

Best Regards,
Chris
Previous Topic:TopLink migration to Eclipselink
Next Topic:Eclipselink 3.0.3 an Java 20
Goto Forum:
  


Current Time: Wed Feb 05 08:56:20 GMT 2025

Powered by FUDForum. Page generated in 0.04700 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top