|Eclipselink queries on DB2 [message #390611]
||Wed, 29 July 2009 15:38
Registered: July 2009
Hello! Our application has successfully worked on both Oracle and |
SQLServer database. Now I need to use DB2 database, also. I have set
target database properties to DB2, created schema and it seemed to work.
But then it turned out that I keep getting error -418 for some queries:
STRING TO BE PREPARED CONTAINS INVALID USE OF PARAMETER MARKERS
Of course, I have looked into it. Google is our friend, but I couldn't
find any reference regarding using toplink/eclipselink. On the other hand,
it turns out that the error is quite common when using pure JDBC and
parameter queries such as mine. References I found say that sometimes DB2
does not know the type of given parameter, so explicit type cast needs to
be done. For instance,
select * from mytable t where t.name like ?
should use explicit cast
select * from mytable t where t.name like (cast ? as varchar(300))
or something like that.
But, I use JPA query language and I don't have control over how my query
is actually translated.
So, does anyone have any experience with DB2 database and these kinds of
queries and could workaround be found?
|Re: Eclipselink queries on DB2 [message #409738 is a reply to message #390611]
||Thu, 30 July 2009 07:59
Registered: July 2009
Here is one of the examples. This is error eclipse returns:|
[EL Warning]: 2009.07.30 09:52:21.265--UnitOfWork(14832679)--Exception
[EclipseLink-4002] (Eclipse Persistence Services
- 1.0.2 (Build 20081024)):
Internal Exception: java.sql.SQLException: [BEA][DB2 JDBC
Driver][DB2]STRING TO BE PREPARED CONTAINS INVALID USE OF PARMETER MARKERS
Error Code: -418
Call: SELECT ID, VERSION, CODE, ROLE, DESCRIPTION, DATASOURCE, TITLESTYLE
FROM RE1REPORT WHERE (((? IS NULL) OR (CODE LIKE ?)) AND ((? IS NULL) OR
(DESCRIPTION LIKE ?)))
bind => [null, null, null, null]
and this is the JPA query:
select r from Report r where (:code is null or r.code like :code)
and (:description is null or r.description like :description)
where :code and :description are given query parameters.
It makes no difference whether you set values to these parameters or leave
Powered by FUDForum
. Page generated in 0.02307 seconds