Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

DB2 CMP vomit-fest -- CASTing in a where like clause?!

843833Jan 31 2005 — edited Oct 15 2009
I'm working with AS8 (build b08-fcs), DB2 Connect 8.2, on Linux (IA32) connecting to a z/os UDB server.

The connection pings, the beans deploy, create / update / etc. works. Data is being commited to the database, and EJB-QL such as the following work flaslessly.
SELECT OBJECT(p) FROM Person AS p
If only everything were so simple.

When I try to do the following query (which worked when we used CMP on a MS-SQL server), things don't go so well.
select object(p) from Person p where p.firstName like ?1
I get the following error:
SQL statement<select t0."DATEOFBIRTH", t0."FIRSTNAME", t0."GENDER", t0."LASTNAME", t0."MIDDLENAME", t0."PERSONID", t0."SALUTATION", t0."SUFFIX" from "PERSON" t0 where t0."FIRSTNAME" like CAST (? AS VARCHAR(32672))> with input values:java.lang.String:Admin%.
Please examine the SQLException for more information.
NestedException: com.ibm.db2.jcc.b.SqlException: DB2 SQL error: SQLCODE: -132, SQLSTATE: 42824, SQLERRMC: null
Why on earth would this be trying to CAST the parameter as a VARCHAR with a maximum length? That seems a bit... stupid. Removing the CAST from my test queries with the db2 control center resulting in accurate responses, adding the CAST resulted in the same error. Following is the table definition for the Person table (where this query is failing).
CREATE TABLE WEBBASE.Person (
	personId INTEGER NOT NULL,
	salutation CHAR(5),
	firstName VARCHAR(50) NOT NULL,
	middleName VARCHAR(15),
	lastName VARCHAR(50) NOT NULL,
	suffix CHAR(3),
	gender SMALLINT NOT NULL,
	dateOfBirth DATE,
	PRIMARY KEY(personId)
) IN WEBBASE.TBSPPRSN;
FYI: Before invoking the finder method, a '%' is prepended to the parameter at ?1. in EJB-QL the query would end up being something along the lines of:
select object(p) from Person p where p.firstName like "%jack"
As I said, this worked fine with MS-SQL...

Any help is greatly appreciated.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 12 2009
Added on Jan 31 2005
10 comments
372 views