Question on EJB-Ql
1 posts in topic
Flat View  Flat View

Posted By:   Javed_Mandary
Posted On:   Sunday, February 9, 2003 09:20 PM

I am relatively new to EJB-Ql this is why i would like to know certain facts.
1. Given I have an SQL query like select * from tbPerson where id=2 order by asc how do i write this in EJB-Ql and perform the order by in ascending order?
2. How do you perform a count a field, that is select count(person.name) from person
3. Is the naming of function executing an EJB-QL depend on the fields it is to return or you can just simply name it the way you want?

Re: Question on EJB-Ql

Posted By:   Anonymous  
Posted On:   Monday, February 10, 2003 02:44 AM

EJB-QL is designed like SQL, so each statement you think in SQL could work same in EJB-QL, ... could!.

Your statement would be
SELECT OBJECT(o) FROM tbPerson AS o WHERE o.id=2 ORDER BY o.name ASC
(I have chosen the field name for sorting), but the ORDER-BY-clause is only valid since EJB 2.1, which isnĀ“t supported by the containers at the moment. EJB 2.1 spec is Proposed Final Draft but not release (as I know).

There is a count function:

The SELECT clause has the following syntax:

select_clause ::=SELECT [DISTINCT ] {select_expression |OBJECT (identification_variable)}
select_expression ::= single_valued_path_expression | aggregate_select_expression
aggregate_select_expression ::= {AVG |MAX |MIN |SUM |COUNT }( [DISTINCT ] cmp_path_expression) | COUNT ( [DISTINCT ] identification_variable | single_valued_cmr_path_expression)

You can name the method like you want. In the deployment descriptor you specify the EJB-QL-string.

I suggest reading the spec chapter 11 "EJB QL: EJB Query Language for Container-Managed Persistence Query Methods".

About | Sitemap | Contact