A workaround for the problem mentioned below is to use addSql:

crit.addSql("upper( INTERNAL_PRODUCT_ID) like '%" + new Integer(
theProductModel.getInternalProductID() ).toString() + "%'" );

Note that in this case you have to use the actual db column name.  Is this
the only solution?

Rgds,
John


-----Original Message-----
From: O'Reilly John [mailto:[EMAIL PROTECTED]
Sent: 26 February 2003 15:22
To: 'OJB Users List'
Subject: addLike and integer fields


Hi,

Is there an issue in OJB with performing like queries with integer fields.
I'm trying to use the following criteria:

crit.addLike( "internalProductID", "%" +
Integer.toString(theProductModel.getInternalProductID()) + "%" );

Query query = new QueryByCriteria(ProductModel.class, crit, true);
Collection lListOfProducts = getBroker().getCollectionByQuery(query);

The field descriptor is as follows:

<field-descriptor name="internalProductID" column="INTERNAL_PRODUCT_ID"
jdbc-type="INTEGER"
                                   primarykey="true"
                                   autoincrement="true"
                                   sequence-name="product_id_seq"/>

When I run the code I above I get an exception (strack trace shown below).
There isn't any issue when I run something like the following sql directly:

select * from products where internal_product_id like '%25%'

Also, the above works fine for 'VARCHAR' fields.

Thanks,
John

java.lang.ClassCastException: java.lang.String  at
oracle.jdbc.driver.OraclePreparedStatement.setObject(OraclePreparedStatement
.java:2021)     at
oracle.jdbc.driver.OraclePreparedStatement.setObject(OraclePreparedStatement
.java:2102)     at
com.p6spy.engine.spy.P6PreparedStatement.setObject(P6PreparedStatement.java:
282)    at
org.apache.ojb.broker.platforms.PlatformDefaultImpl.setObjectForStatement(Pl
atformDefaultImpl.java:229)     at
org.apache.ojb.broker.platforms.PlatformOracleImpl.setObjectForStatement(Pla
tformOracleImpl.java:126)       at
org.apache.ojb.broker.accesslayer.StatementManager.bindStatementValue(Statem
entManager.java:258)    at
org.apache.ojb.broker.accesslayer.StatementManager.bindStatement(StatementMa
nager.java:297)         at
org.apache.ojb.broker.accesslayer.StatementManager.bindSelectionCriteria(Sta
tementManager.java:490)         at
org.apache.ojb.broker.accesslayer.StatementManager.bindStatement(StatementMa
nager.java:451)         at
org.apache.ojb.broker.accesslayer.JdbcAccessImpl.executeQuery(JdbcAccessImpl
.java:258)      at
org.apache.ojb.broker.accesslayer.RsIterator.<init>(RsIterator.java:175)
at
org.apache.ojb.broker.singlevm.RsIteratorFactoryImpl.createRsIterator(RsIter
atorFactoryImpl.java:95)        at
org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.getRsIteratorFromQuery(
PersistenceBrokerImpl.java:2146)        at
org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.getIteratorFromQuery(Pe
rsistenceBrokerImpl.java:1550)  at
org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.getCollectionByQuery(Pe
rsistenceBrokerImpl.java:1235)  at
org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.getCollectionByQuery(Pe
rsistenceBrokerImpl.java:1363)  at
org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.getCollectionByQuery(Pe
rsistenceBrokerImpl.java:1389)  at
org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.getCollectionByQuery(Pe
rsistenceBrokerImpl.java:1376)  at
org.apache.ojb.broker.singlevm.DelegatingPersistenceBroker.getCollectionByQu
ery(DelegatingPersistenceBroker.java:294)       at
ie.mcps.product.dao.ProductDAO.searchForProduct(ProductDAO.java:509)
************************************************************************
This e-mail and any files transmitted with it are confidential and may be
privileged and are intended solely for the individual named/ for the use of
the individual or entity to whom they are addressed.If you are not the
intended addressee, you should not disseminate, distribute or copy this
e-mail.Please notify the sender immediately if you have received this e-mail
by mistake and delete this e-mail from your system.If you are not the
intended recipient, you are notified that reviewing, disclosing, copying,
distributing or taking any action in reliance on the contents of this e-mail
is strictly prohibited.Please note that any views or opinions expressed in
this e-mail are solely those of the author and do not necessarily represent
those of Traventec Limited.E-mail transmission cannot be guaranteed to be
secure or error-free as information could be intercepted, corrupted, lost,
destroyed, or arrive late or incomplete.Traventec Limited therefore does not
accept liability for any errors or omissions in the contents of this
message, which arise as a result of e-mail transmission.The recipient should
check this e-mail and any attachments for the presence of viruses.This
e-mail has been swept for computer viruses however Traventec Limited accepts
no liability for any damage caused by any virus transmitted by this e-mail.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
************************************************************************
This e-mail and any files transmitted with it are confidential and may be
privileged and are intended solely for the individual named/ for the use of
the individual or entity to whom they are addressed.If you are not the
intended addressee, you should not disseminate, distribute or copy this
e-mail.Please notify the sender immediately if you have received this e-mail
by mistake and delete this e-mail from your system.If you are not the
intended recipient, you are notified that reviewing, disclosing, copying,
distributing or taking any action in reliance on the contents of this e-mail
is strictly prohibited.Please note that any views or opinions expressed in
this e-mail are solely those of the author and do not necessarily represent
those of Traventec Limited.E-mail transmission cannot be guaranteed to be
secure or error-free as information could be intercepted, corrupted, lost,
destroyed, or arrive late or incomplete.Traventec Limited therefore does not
accept liability for any errors or omissions in the contents of this
message, which arise as a result of e-mail transmission.The recipient should
check this e-mail and any attachments for the presence of viruses.This
e-mail has been swept for computer viruses however Traventec Limited accepts
no liability for any damage caused by any virus transmitted by this e-mail.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to