| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| The API doc seems to indicate that the default attribute for addLike() is the name of the class member. However it only works for me if I use the column name. In the example below the getCount() fails (with ClassCastException) for count1 and count2 (which use the class attribute "listingId") but succeed for count3 (which uses the column name LID); Below is a snippet of the repository and test example code and a stack trace. The stack trace shows that some of the apache classes have been replaced. Perhaps the problem is there. Can anyone verify offhand that the count2 query should work? <class-descriptor class="com.syms.business.model.BaseWPListings" table="wp_listings" schema="ypas" refresh="false" > <field-descriptor id="1" name="listingId" column="LID" jdbc-type="NUMERIC" nullable="false" primarykey="true" /> <field-descriptor id="2" name="setId" column="SETID" jdbc-type="NUMERIC" nullable="false" /> <!-- ... --> </class-descriptor> public static String testColumAttribute2() { logger.debug("In testColumAttribute()"); PersistenceBroker broker = null; String progress = ""; try { broker = PersistenceBrokerFactory.defaultPersistenceBroker( ); Class cls = BaseWPListings.class; String attr1 = "listingId"; // This is the class member name String attr2 = "LID"; // This is the corresponding column name String column1 = "listingId"; // This is the class member name String column2 = "LID"; // This is the corresponding column name String value = "3689737"; String[] selectColumns1 = { column1 }; String[] selectColumns2 = { column2 }; //----------------------------- try { Criteria criteria1 = new Criteria(); criteria1.addLike(attr1, value); Query query1 = QueryFactory.newReportQuery(cls, selectColumns1, criteria1, true); int count1 = broker.getCount(query1); progress += "count1=" + count1; } catch (Throwable t) { String errorKey = "wp_listings"; logger.error("error in testColumAttribute() ", t); } //----------------------------- try { Criteria criteria2 = new Criteria(); criteria2.addLike(attr1, value); Query query2 = QueryFactory.newReportQuery(cls, selectColumns2, criteria2, true); int count2 = broker.getCount(query2); progress += "count2=" + count2; } catch (Throwable t) { String errorKey = "wp_listings"; logger.error("error in testColumAttribute() ", t); } //----------------------------- try { Criteria criteria3 = new Criteria(); criteria3.addLike(attr2, value); Query query3 = QueryFactory.newReportQuery(cls, selectColumns2, criteria3, true); int count3 = broker.getCount(query3); progress += "count3=" + count3; } catch (Throwable t) { String errorKey = "wp_listings"; logger.error("error in testColumAttribute() ", t); } } catch (Throwable t) { String errorKey = "wp_listings"; logger.error("error in testColumAttribute() ", t); } finally { if (broker != null) { broker.close(); } logger.debug("progress=" + progress); } return progress; } 17 01:10:08,140 DEBUG .delegate.WPListingsBusinessDelegate - In testColumAttribute() 17 01:10:08,140 DEBUG .PersistenceBrokerFactoryDefaultImpl - Obtain broker from pool, used PBKey is org.apache.ojb.broker.PBKey: jcdAlias=syms, user=null, password=null 17 01:10:08,140 DEBUG siness.ojb.SymsPersistenceBrokerImpl - getCount class com.syms.business.model.BaseWPListings, ReportQuery from class com.syms.business.model.BaseWPListings count(distinct listingId) where[listingId LIKE 3689737] 17 01:10:08,140 DEBUG siness.ojb.SymsPersistenceBrokerImpl - Creating RsIterator for class [com.syms.business.model.BaseWPListings] 17 01:10:08,140 DEBUG syms.business.ojb.SymsJdbcAccessImpl - executeQuery : ReportQuery from class com.syms.business.model.BaseWPListings count(distinct listingId) where[listingId LIKE 3689737] 17 01:10:08,140 DEBUG yer.sql.SqlQueryStatement$TableAlias - TableAlias(): using hints ? false 17 01:10:08,140 DEBUG ness.ojb.SymsSqlGeneratorDefaultImpl - SQL:SELECT count(distinct A0.LID) FROM ypas.wp_listings A0 WHERE A0.LID LIKE ? 17 01:10:08,140 DEBUG slayer.ConnectionFactoryAbstractImpl - do datasource lookup, name: java:comp/env/jdbc/syms, user: null 17 01:10:08,150 DEBUG slayer.ConnectionFactoryAbstractImpl - Create new connection using DataSource: org.apache.commons.dbcp.PoolableConnection@125ee49 17 01:10:08,150 DEBUG er.accesslayer.ConnectionManagerImpl - Request new connection from ConnectionFactory: org.apache.commons.dbcp.PoolableConnection@125ee49 17 01:10:08,150 ERROR .delegate.WPListingsBusinessDelegate - error in testColumAttribute() java.lang.ClassCastException at oracle.jdbc.driver.OraclePreparedStatement.setObje ct(OraclePreparedStatement.java:1956) at oracle.jdbc.driver.OraclePreparedStatement.setObje ct(OraclePreparedStatement.java:2052) at org.apache.commons.dbcp.DelegatingPreparedStatemen t.setObject(DelegatingPreparedStatement.java:162) at org.apache.ojb.broker.platforms.PlatformDefaultImp l.setObjectForStatement(Unknown Source) at org.apache.ojb.broker.platforms.PlatformOracleImpl .setObjectForStatement(Unknown Source) at com.syms.business.ojb.SymsStatementManager.bindSta tementValue(SymsStatementManager.java:242) at com.syms.business.ojb.SymsStatementManager.bindSta tement(SymsStatementManager.java:274) at com.syms.business.ojb.SymsStatementManager.bindSel ectionCriteria(SymsStatementManager.java:450) at com.syms.business.ojb.SymsStatementManager.bindSta tement(SymsStatementManager.java:414) at com.syms.business.ojb.SymsStatementManager.bindSta tement(SymsStatementManager.java:387) at org.apache.ojb.broker.accesslayer.JdbcAccessImpl.e xecuteQuery(Unknown Source) at org.apache.ojb.broker.accesslayer.RsQueryObject.pe rformQuery(Unknown Source) at com.syms.business.ojb.RsIterator.<init>(RsIterator .java:169) at com.syms.business.ojb.ReportQueryRsIterator.<init> (ReportQueryRsIterator.java:32) at com.syms.business.ojb.ReportRsIteratorFactoryImpl. createRsIterator(ReportRsIteratorFactoryImpl.java: 54) at com.syms.business.ojb.SymsPersistenceBrokerImpl.ge tRsIteratorFromQuery(SymsPersistenceBrokerImpl.jav a:1602) at com.syms.business.ojb.SymsPersistenceBrokerImpl.ge tReportQueryIteratorFromQuery(SymsPersistenceBroke rImpl.java:1651) at com.syms.business.ojb.SymsPersistenceBrokerImpl.ge tReportQueryIteratorByQuery(SymsPersistenceBrokerI mpl.java:1577) at com.syms.business.ojb.SymsPersistenceBrokerImpl.ge tCount(SymsPersistenceBrokerImpl.java:1548) at org.apache.ojb.broker.core.DelegatingPersistenceBr oker.getCount(Unknown Source) at org.apache.ojb.broker.core.DelegatingPersistenceBr oker.getCount(Unknown Source) at com.syms.business.delegate.WPListingsBusinessDeleg ate.testColumAttribute2(WPListingsBusinessDelegate .java:514) |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.