Re: urgent! pls help! some questions about EJB QL

From: Christopher Blunck (blunck_at_gst.com)
Date: 10/22/03


Date: Wed, 22 Oct 2003 00:14:39 -0400

On Thu, 25 Sep 2003 20:57:25 -0700, maggie2003 wrote:

> Hello,
>
> I'm new learner on EJB and now I'm working on a project which need to
> do SQL to EJB QL translation. I went through the specification 2.0 of
> EJB QL released by Sun, I'm not quite understand the following words
> regarding to the SELECT clause of EJB QL:
>
> "In the case of a find method, the SELECT clause is restricted to
> contain either a single range variable or a single value path
> expression that evaluates to the abstract schema type of the entity
> bean for which the finder method is defined.
> Because finder method cannot return arbitrary types, the SELECT clause
> of an EJB QL defined for a finder method must always correspond to the
> abstract shcema type fo the entity bean for which the finder method is
> defined.In contrast, the SELECT clause of a query defined for a select
> method can return the abstract schema types of other entity beans or
> the values of cmp-fields."
>
> As my understanding, I think the SELECT clause of finder method can
> only contain a single range variable instead of single value path
> expresson, it should have only one format, which is "SELECT [DISTINCT]
> OBJECT(identification_variable)".
>
> For example: the query below is defined in OrderBean
> findByProductType();
> SELECT OBJECT(o) FROM Order o, IN(o.lineItems) l
> WHERE l.product.product_type = 'schoolsupplies'
>
> how it could be a single value path expression , I think this format
> can only be used in Select method.
>
> Another question is, EJB QL 2.0 does not support subquery and EXIST,
> does this mean that a SQL query with subquery or EXIST clause can't be
> translated to EJB QL?
>
> I don't know if I'm correct or not. I'd appreciate if anybody can help
> me with this.
>
> Thanks!
> Maggie

Hi Maggie-

My background is with BEA WebLogic 7.0 and TopLink 9.0.3 CMP, so take
everything I say with a grain of salt because TopLink certainly has lots
of "features" that are not part of core J2EE, but it also does not
implement items that are supposed to exist in J2EE. That being said, I
struggled with EJB QL syntax and had a hard time locating information on
the net, so I am very sympathetic to your situation and would like to
share the information I have.

What it looks like you are trying to do is to locate orders containing a
line item, which has a product who's product_type is 'schoolsupplies'.

Your EJB QL looks fine to me. Does the finder not work properly?

As for your second question about subqueries and exist - you are correct.
Some SQL queries simply cannot be translated to EJB QL 2.0. There are
several limitations in the current EJB QL spec (most notably the lack of
time support for comparisons (!!)) - they'll get better over time tho.

In the meantime, most vendors I believe offer some way of issuing SQL to
augment your EJB QL. TopLink does.

-c



Relevant Pages

  • Re: Newbie question about EJB-CMP: is it worth it when using multiple containers?
    ... > supports multiple EJB containers, ... How complex should my SQL be ... CMP EJBs are just another abstraction layer atop proprietary RDBMS ... You write your queries in EJB QL rather than SQL and the ...
    (comp.lang.java.programmer)
  • Re: Newbie question about EJB-CMP: is it worth it when using multiple containers?
    ... >> supports multiple EJB containers, ... >> should my SQL be to make CMP really valuable in this case? ... > CMP EJBs are just another abstraction layer atop proprietary RDBMS ... You write your queries in EJB QL rather than SQL and the ...
    (comp.lang.java.programmer)
  • Re: EJB
    ... Why is the EJB ... It is usually a lot slower than direct JDBC ... When using EJBs you can write your own SQL or use generated SQL. ... In the projects I work in we use all three versions of EJB plus direct ...
    (comp.lang.java.programmer)