Parameters in RawSql

1,304 views
Skip to first unread message
Message has been deleted
Message has been deleted

Claudio Lezcano

unread,
Feb 1, 2012, 6:56:38 PM2/1/12
to Ebean ORM
Hi everybody, I have the next raw sql:
String sql = "SELECT A.NAME, B.PERSON_ID "
+ " FROM A, B,"
+ "WHERE B.ID = A.ID "
+" AND B.ID > :param";
RawSql rawSql =

RawSqlBuilder.parse(sql).columnMapping("A.NAME","customerName").create();

Query<Persons> query = Ebean.find(Persons.class);
query.setRawSql(rawSql);
query.setParameter("param", 0);
list = query.findList();

I get the next exception:

"Query threw SQLException:Invalid column index
Bind values:[0, ]
Query was:
select A.NAME, B.PERSON_ID
FROM A, B,
WHERE B.ID = A.ID
AND B.ID > ?

"

could someone help me please?
Regards.

Rob Bygrave

unread,
Feb 2, 2012, 6:24:01 AM2/2/12
to eb...@googlegroups.com
Hmm. You are only mapping one of the columns - that could be an issue.

Your code doesn't look quite right. The type of the query [LicensesSales] is different to the class passed to the find [Persons] - so I don't that should compile?



On 1 February 2012 12:42, claudio lezcano <claud...@gmail.com> wrote:
Just a little aclaration, the type of the query is Person, the query doesn't take parameters, but without them (the parameters), the query runs ok and retrieve mapped rows.


2012/1/31 Claudio Lezcano <claud...@gmail.com>
Hi everybody i have some problems setting parameters into a query
builded from a raw query, the specific case is:


String sql = "SELECT A.NAME, B.PERSON_ID "
                   + " FROM  A, B,"
                   + "WHERE B.ID = A.ID "
                   +" AND B.ID > :param";
                 RawSql rawSql =
                   RawSqlBuilder.parse(sql).columnMapping("A.NAME",
"customerName").create();

           Query<LicensesSales> query = Ebean.find(Persons.class);

           query.setRawSql(rawSql);
           query.setParameter("param", 0);
           list = query.findList();

I get the next exception:

"Query threw SQLException:Invalid column index
Bind values:[0, ]
Query was:
select  A.NAME, B.PERSON_ID
                   FROM  A, B,
                   WHERE B.ID = A.ID
                   AND B.ID > ?

"

could someone help me please?
Regards.



--

Atte.

Claudio Lezcano

claud...@gmail.com

Tel.: (595 985) 729 683



Claudio Lezcano

unread,
Feb 2, 2012, 8:40:43 AM2/2/12
to Ebean ORM
True, i made this as an example, the code must be:
String sql = "SELECT A.NAME "
+ " FROM A,"
+ "WHERE A.ID = :param";
RawSql rawSql =
RawSqlBuilder.parse(sql).columnMapping("A.NAME","name").create();
Query<Persons> query = Ebean.find(Persons.class);
query.setRawSql(rawSql);
query.setParameter("param", 0);
list = query.findList();

the exception is:

"Query threw SQLException:Invalid column index
Bind values:[0, ]
Query was:
select A.NAME FROM A
WHERE A.ID = ?
"

The issue is that, without the parameter (":param") and setParameter
in the query, the query runs ok and return mapped entities, but when i
try to set a parameter this way, throws an exception.
I saw an enhacement with number 304 (in the avagé page) presumably
solved this issue in the 2.7.0, (i using the 2.7.4).
In brief, Iam confused.
Please some help.

On 2 feb, 08:24, Rob Bygrave <robin.bygr...@gmail.com> wrote:
> Hmm. You are only mapping one of the columns - that could be an issue.
>
> Your code doesn't look quite right. The type of the query [LicensesSales]
> is different to the class passed to the find [Persons] - so I don't that
> should compile?
>
> On 1 February 2012 12:42, claudio lezcano <claudio...@gmail.com> wrote:
>
>
>
>
>
>
>
> > Just a little aclaration, the type of the query is Person, the query
> > doesn't take parameters, but without them (the parameters), the query runs
> > ok and retrieve mapped rows.
>
> > 2012/1/31 Claudio Lezcano <claudio...@gmail.com>
>
> >> Hi everybody i have some problems setting parameters into a query
> >> builded from a raw query, the specific case is:
>
> >> String sql = "SELECT A.NAME, B.PERSON_ID "
> >>                    + " FROM  A, B,"
> >>                    + "WHERE B.ID = A.ID "
> >>                    +" AND B.ID > :param";
> >>                  RawSql rawSql =
> >>                    RawSqlBuilder.parse(sql).columnMapping("A.NAME",
> >> "customerName").create();
>
> >>            Query<LicensesSales> query = Ebean.find(Persons.class);
> >>            query.setRawSql(rawSql);
> >>            query.setParameter("param", 0);
> >>            list = query.findList();
>
> >> I get the next exception:
>
> >> "Query threw SQLException:Invalid column index
> >> Bind values:[0, ]
> >> Query was:
> >> select  A.NAME, B.PERSON_ID
> >>                    FROM  A, B,
> >>                    WHERE B.ID = A.ID
> >>                    AND B.ID > ?
>
> >> "
>
> >> could someone help me please?
> >> Regards.
>
> > --
>
> > *Atte.*
> > *
>
> > Claudio Lezcano
>
> > claudio...@gmail.com
>
> > Tel.: (595 985) 729 683
> > *

Claudio Lezcano

unread,
Feb 2, 2012, 8:52:41 AM2/2/12
to Ebean ORM
http://www.avaje.org/bugdetail-304.html, this is an complete example
of what i try to do and can´t.
It appears with state FIXED, but i can´t use this feature.
Regards.
Reply all
Reply to author
Forward
0 new messages