You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Harri Kaimio <ha...@kolumbus.fi> on 2006/01/22 16:18:25 UTC

SQL functions with multiple parameters & OJB 1.0.x

Hi,

I am having problems with OJB query criterias that include SQL functions 
with several parameters. Here is an actual example that does not work:

crit.addGreaterOrEqualThan( "subdate("+dateField.getName()
                    + ", " + accuracyField.getName() + ")",
                    date );

creates an exception like this:

java.lang.StringIndexOutOfBoundsException: String index out of range: -2
        at java.lang.String.substring(String.java:1768)
        at org.apache.ojb.broker.util.SqlHelper.splitPath(Unknown Source)
        at org.apache.ojb.broker.util.SqlHelper.cleanPath(Unknown Source)
        at 
org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.buildJoinTreeForColumn(Unknown 
Source)
        at 
org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.buildJoinTree(Unknown 
Source)
        at 
org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.splitCriteria(Unknown 
Source)
        at 
org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.<init>(Unknown 
Source)
        at 
org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.<init>(Unknown 
Source)
        at 
org.apache.ojb.broker.accesslayer.sql.SqlSelectStatement.<init>(Unknown 
Source)
        at 
org.apache.ojb.broker.accesslayer.sql.SqlGeneratorDefaultImpl.getPreparedSelectStatement(Unknown 
Source)
        at 
org.apache.ojb.broker.accesslayer.JdbcAccessImpl.executeQuery(Unknown 
Source)
        at 
org.apache.ojb.broker.accesslayer.RsQueryObject.performQuery(Unknown Source)
        at org.apache.ojb.broker.accesslayer.RsIterator.<init>(Unknown 
Source)
        at 
org.apache.ojb.broker.core.RsIteratorFactoryImpl.createRsIterator(Unknown 
Source)
        at 
org.apache.ojb.broker.core.PersistenceBrokerImpl.getRsIteratorFromQuery(Unknown 
Source)
        at 
org.apache.ojb.broker.core.PersistenceBrokerImpl.getIteratorFromQuery(Unknown 
Source)
        at 
org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQuery(Unknown 
Source)
        ... 25 more

Based on mail archives & error database this problem seems to be similar 
to issue OJB-4 which should be fixed in 1.1 branch. However, I am 
otherwise happy with OJB 1.0.4 and not particularly willing to migrate 
into non-production branch. So, is there any plan to get the fix into 
1.0.x? Or any other workaround than using native SQL criteria?

BR, Harri


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: SQL functions with multiple parameters & OJB 1.0.x

Posted by Carlos Chávez <cc...@agssa.net>.
Harri Kaimio wrote:

> Hi,
>
> I am having problems with OJB query criterias that include SQL 
> functions with several parameters. Here is an actual example that does 
> not work:
>
> crit.addGreaterOrEqualThan( "subdate("+dateField.getName()
>                    + ", " + accuracyField.getName() + ")",
>                    date );

Hi Harri,

try to avoid the resolution of the name that OJB do,
write directly the name of the column in the table.

That work for me in the list of attribute, i don't try in the criteria.

I hope this help.

Cheers,
Carlos Chávez.

>
> creates an exception like this:
>
> java.lang.StringIndexOutOfBoundsException: String index out of range: -2
>        at java.lang.String.substring(String.java:1768)
>        at org.apache.ojb.broker.util.SqlHelper.splitPath(Unknown Source)
>        at org.apache.ojb.broker.util.SqlHelper.cleanPath(Unknown Source)
>        at 
> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.buildJoinTreeForColumn(Unknown 
> Source)
>        at 
> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.buildJoinTree(Unknown 
> Source)
>        at 
> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.splitCriteria(Unknown 
> Source)
>        at 
> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.<init>(Unknown 
> Source)
>        at 
> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.<init>(Unknown 
> Source)
>        at 
> org.apache.ojb.broker.accesslayer.sql.SqlSelectStatement.<init>(Unknown 
> Source)
>        at 
> org.apache.ojb.broker.accesslayer.sql.SqlGeneratorDefaultImpl.getPreparedSelectStatement(Unknown 
> Source)
>        at 
> org.apache.ojb.broker.accesslayer.JdbcAccessImpl.executeQuery(Unknown 
> Source)
>        at 
> org.apache.ojb.broker.accesslayer.RsQueryObject.performQuery(Unknown 
> Source)
>        at org.apache.ojb.broker.accesslayer.RsIterator.<init>(Unknown 
> Source)
>        at 
> org.apache.ojb.broker.core.RsIteratorFactoryImpl.createRsIterator(Unknown 
> Source)
>        at 
> org.apache.ojb.broker.core.PersistenceBrokerImpl.getRsIteratorFromQuery(Unknown 
> Source)
>        at 
> org.apache.ojb.broker.core.PersistenceBrokerImpl.getIteratorFromQuery(Unknown 
> Source)
>        at 
> org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQuery(Unknown 
> Source)
>        ... 25 more
>
> Based on mail archives & error database this problem seems to be 
> similar to issue OJB-4 which should be fixed in 1.1 branch. However, I 
> am otherwise happy with OJB 1.0.4 and not particularly willing to 
> migrate into non-production branch. So, is there any plan to get the 
> fix into 1.0.x? Or any other workaround than using native SQL criteria?
>
> BR, Harri
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: SQL functions with multiple parameters & OJB 1.0.x

Posted by Jakob Braeuchi <jb...@gmx.ch>.
hi harri,

as you say, this is a known problem with ojb 1.0.x.
i'll try to backport from ojb 1.x as soon as time allows.

jakob

Harri Kaimio schrieb:
> Hi,
> 
> I am having problems with OJB query criterias that include SQL functions 
> with several parameters. Here is an actual example that does not work:
> 
> crit.addGreaterOrEqualThan( "subdate("+dateField.getName()
>                    + ", " + accuracyField.getName() + ")",
>                    date );
> 
> creates an exception like this:
> 
> java.lang.StringIndexOutOfBoundsException: String index out of range: -2
>        at java.lang.String.substring(String.java:1768)
>        at org.apache.ojb.broker.util.SqlHelper.splitPath(Unknown Source)
>        at org.apache.ojb.broker.util.SqlHelper.cleanPath(Unknown Source)
>        at 
> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.buildJoinTreeForColumn(Unknown 
> Source)
>        at 
> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.buildJoinTree(Unknown 
> Source)
>        at 
> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.splitCriteria(Unknown 
> Source)
>        at 
> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.<init>(Unknown 
> Source)
>        at 
> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.<init>(Unknown 
> Source)
>        at 
> org.apache.ojb.broker.accesslayer.sql.SqlSelectStatement.<init>(Unknown 
> Source)
>        at 
> org.apache.ojb.broker.accesslayer.sql.SqlGeneratorDefaultImpl.getPreparedSelectStatement(Unknown 
> Source)
>        at 
> org.apache.ojb.broker.accesslayer.JdbcAccessImpl.executeQuery(Unknown 
> Source)
>        at 
> org.apache.ojb.broker.accesslayer.RsQueryObject.performQuery(Unknown 
> Source)
>        at org.apache.ojb.broker.accesslayer.RsIterator.<init>(Unknown 
> Source)
>        at 
> org.apache.ojb.broker.core.RsIteratorFactoryImpl.createRsIterator(Unknown 
> Source)
>        at 
> org.apache.ojb.broker.core.PersistenceBrokerImpl.getRsIteratorFromQuery(Unknown 
> Source)
>        at 
> org.apache.ojb.broker.core.PersistenceBrokerImpl.getIteratorFromQuery(Unknown 
> Source)
>        at 
> org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQuery(Unknown 
> Source)
>        ... 25 more
> 
> Based on mail archives & error database this problem seems to be similar 
> to issue OJB-4 which should be fixed in 1.1 branch. However, I am 
> otherwise happy with OJB 1.0.4 and not particularly willing to migrate 
> into non-production branch. So, is there any plan to get the fix into 
> 1.0.x? Or any other workaround than using native SQL criteria?
> 
> BR, Harri
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
> 
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org