Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Named parameters and createNativeQuery does not work with PostgreSQL

Hi Andreas,

  We use the "?" character for parameters on native queries.

http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Basic_JPA_Development/Querying/Native

-Tom

On 19/08/2013 10:14 AM, Andreas Joseph Krogh wrote:
Hi.
 
I have this native-query (I use Scala-JPA, which is a thin wrapper):
 
entityManager.createNativeQuery[Boolean](
        """SELECT s.is_seen
    FROM origo_email_message_property s
   WHERE s.owner_id = :ownerId AND s.message_id  = :messageId""").
        setParams("ownerId" -> owner.id, "messageId" -> messageId)
Which results in this SQLException using PostgreSQL:
 
Internal Exception: java.sql.SQLException: syntax error at or near ":"
Error Code: 0
Call: SELECT s.is_seen
                             FROM origo_email_message_property s
                            WHERE s.owner_id = :ownerId AND s.message_id  = :messageId
 
It seems EL sends the query unmodified to PG and PG doesn't support :<param_name> syntax, only indexed (as in "where id = ?"). Hibernate handles this quite nicely and rewrites the query if necessary it seems.
 
Is this a known issue using PG and one has to use indexed instead of named params in native-queries?
 
Thanks.
 
--
Andreas Joseph Krogh <andreak@xxxxxxxxxxxx>      mob: +47 909 56 963
Senior Software Developer / CTO - OfficeNet AS - http://www.officenet.no
Public key: http://home.officenet.no/~andreak/public_key.asc


_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users


Back to the top