On Aug 14, 10:49 am, Freewind <
nowind...@gmail.com> wrote:
> I have looked for these in the User- Guide, but not found.
True, it's not documented.
> For this question, can I treat it as a kind of bug?
No, it's a *feature*, not a *bug* :-) here's why.
In a "standard" ORM query language, it is the object model that is
queried, not the database model. This is what your query might look
like in JPA:
select v from Vote as v
where v.question_id = :qId
and v.user_id = :uId
(then set the named parameters for the question id and user id)
This query would fail the parsing phase (in the ORM, before going to
SQL) because "question_id" is not a property of Vote. The query should
be like this:
select v from Vote as v
where
v.question.id = :qId
and
v.user.id = :uId
So JPA would fail to parse question_id (and user_id) and throw an
error. Here, Ebean fails to parse question_id but instead of throwing
an error, it passes the unparseable content through to the generated
SQL. Here's the feature part. Imagine you have a custom function in
the database called "transmogrify", and you wrote a query like this:
Ebean.find(Vote.class).where().eq("transmogrify(
user.name)",
"XYZ123")...
Assuming User has a "name" field, Ebean would parse
user.name and
generate the appropriate SQL along with necessary joins to properly
reference it. But Ebean fails to parse transmogrify and passes it
through to the SQL. The result is that you can mix SQL with the ORM.
So you might end up with a SQL query like this:
select
v.id as c1, ...
from Votes as v
join Users as u on u.user_id = v.user_id
where transmogrify(
u.name) = ?
The "problem" with this feature is that when you make a mistake, the
error thrown (by the database driver) is not very helpful.
Ebean.find(Vote.class).where().eq("ufer.fame", "XYZ123")...
Here I've spelled
user.name wrong and Ebean just sends it through and
I have to look a little harder to figure out what went wrong.
/Daryl