Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8434701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:43:46+00:00 2026-06-10T06:43:46+00:00

This is my PostgreSQL function: salvarArquivoGeometricoCasoZeroPOINT (dimensao text,tableName text,tuplas text[],srid text) It has a

  • 0

This is my PostgreSQL function:

salvarArquivoGeometricoCasoZeroPOINT
(dimensao text,tableName text,tuplas text[],srid text)

It has a text[] parameter, and I want to pass a Java String[] to it from my JPQL:

public String salvarGeometriaCaso0(String[] tuplas,FileDto arquivo){
        Query query =
        em().createNativeQuery("select 
salvarArquivoGeometricoCasoZeroPOINT(?1,?2,?3,?4)");
        query.setParameter(1,arquivo.getGeo());//String
        query.setParameter(2,arquivo.getTable());/String
        query.setParameter(3,tuplas);//String[]
        query.setParameter(4,arquivo.getSrid());//String
        return (String) query.getSingleResult();//function returns a Text, so cast to String
}

The above code fails with the exception:

ERROR] Internal Exception: org.postgresql.util.PSQLException: Can not infer a SQL
type to use for an instance of [Ljava.lang.String;. 
Use setObject () with an explicit Types value to specify the type to use.

so I’m not sure how to call my function from EclipseLink.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T06:43:47+00:00Added an answer on June 10, 2026 at 6:43 am

    Testing by passing a Java array of type String[] to PreparedStatement.setObject(...) results in the behaviour you report. It appears that PgJDBC doesn’t accept a Java array as an argument to PreparedStatement.setObject(), with or without a Types.ARRAY parameter.

    Compliance

    The JDBC spec, 16.5 “Array Objects”, suggests that the JDBC Array exists partly so the client doesn’t have to copy big arrays into memory, they can be used by reference. I’m not too sure whether the JDBC driver is required to accept raw Java arrays as parameters. All the spec code refers to java.sql.Array and the spec makes it clear that arrays are mapped via the Array interface in Appendix B and elsewhere. In a quick search/reading I could find no mention of passing raw Java arrays other than byte[] as parameters or returning them as results.

    However, in §16.5.4 the JDBC4.2 draft spec reads:

    A Java array may be passed as an input parameter by calling the method
    PreparedSatement.setObject.
    

    though all the rest of the code there refers to Array objects. Do they mean Array by “a Java array”? Or do they mean a raw native Java array like String[]?

    It looks to me like clients are supposed to use the java.sql.Array interface via Connection.createArrayOf(...), so EclipseLink is probably doing the wrong thing.

    What do do about it

    Try updating EclipseLink to 2.4 in the hopes it uses the commonly specified method of passing arrays to JDBC via a java.sql.Array object.

    You may also need to annotate the mapping with @Array, an EclipseLink extension. See also this forum thread re 2.3 and bug 361701.

    It appears you may have to implement your own type handler for EclipseLink to override its behaviour. To correctly set an array parameter via PgJDBC you must use:

        Array sqlArray = conn.createArrayOf("text", strArray);
        pstmt.setArray(1, sqlArray);
        pstmt.executeUpdate();
    

    … where conn and pstmt are a java.sql.Connection and a PreparedStatement respectively, and strArray is a String[] instance.

    See Custom data types in the eclipselink wiki.

    On a side note, the use of a string type name to specify the array’s data type in createArrayOf seems kind of insane given the existence of java.sql.Types. It makes portability much harder; the above code won’t run on (say) Oracle, because Oracle wants VARCHAR not text as a type name.


    Note: The unit test org/postgresql/test/jdbc2/ArrayTest.java has ArrayTest.testSetArray(), which at line 166 tests:

        pstmt.setObject(1, arr);
        pstmt.executeUpdate();
    

    … however the type of arr is java.sql.Array, not int[]. It’s a JDBC array type, not a regular Java array.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to do something like this in PostgreSQL. I tried this: CREATE or
I just want an update trigger like this postgresql version... It seems to me
I have this function in PostgreSQL, but I don't know how to return the
Iam having problem creating postgresql function in plperl CREATE OR REPLACE FUNCTION zm_json (TEXT,
Given this string HELLO水 Legend: http://en.wikipedia.org/wiki/UTF-16 is 4 bytes 水 is 2 bytes Postgresql
In PostgreSQL, there is this very useful string_agg function, that allows query like: SELECT
I'm facing an issue with the exponential function in postgresql. If I use this
I have a Postgresql PL/pgSQL function that has a double nested FOR loop, where
I have a Postgresql function which returns a composite type defined as (location TEXT,
I am just starting out on functions in PostgreSQL, and this is probably pretty

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.