Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How i use order by clause with input parameter in EJB2.0  RSS feed

 
Ashutosh kumar singh
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am using EJB2.0 but i am unable to set order by clause with input parameter. simply order by in runing.......... but when i am use input parameter then deployment error

Example : select Object(o) from Employee o where o.employeeno like ?1 order by o.employeename

If any body have idea about this then please forward your idea.

Periorty == URGENT
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unfortunately The EJB 2.x spec does not allow you to use Input parameters with LIKE clauses.
 
Scott Selikoff
author
Bartender
Posts: 4087
21
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Martijn Verburg:
Unfortunately The EJB 2.x spec does not allow you to use Input parameters with LIKE clauses.


Yes it does. Read here for API.

For ordering, have you tried "ORDER BY o.employeename ASC"?
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Scott Selikoff:


Yes it does. Read here for API.


I'm pretty sure that input parameters with the LIKE clause is unsupported.

The LIKE operator compares a String type CMP field to a String literal. It therefore cannot be used in comparison with an input parameter because the input parameter by definition is unknown until the method is invoked.

Richard Monson-Haeful points this out in his Oreilly's Enterprise Javabeans 4th Edition, it's a nasty gotcha!
 
Scott Selikoff
author
Bartender
Posts: 4087
21
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Martijn Verburg:
I'm pretty sure that input parameters with the LIKE clause is unsupported


Hmmm, I'm going to file this as one of those things the spec supports, but specific application servers may or may not support it properly. Either way, the spec does specifically mention it: EJB 2.0 Final Release 2, Section 11.2.7.9.
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Scott Selikoff:


Hmmm, I'm going to file this as one of those things the spec supports, but specific application servers may or may not support it properly. Either way, the spec does specifically mention it: EJB 2.0 Final Release 2, Section 11.2.7.9.


This is definitely interesting! I remember running across this years ago when I first went through the R M-H book. I took a look at the EJB spec section but I can't see where it states that supports input parameters?

I can see that it supports the usual SQL LIKE wildcards e.g. '%<substring>%' but that's subtly different to taking an input parameter e.g. %1

The syntax for the use of the comparison operator [NOT] LIKE in a conditional expression is as follows:

single_valued_path_expression [NOT] LIKE pattern-value [ESCAPE escape-character]

The single_valued_path_expression must have a String value. The pattern-value is a string literal in which an underscore (_) stands for any single character, a percent (%) character stands for any sequence of characters (including the empty sequence), and all other characters stand for themselves. The optional escape-character is a single character string literal and is used to escape the special meaning of the underscore and percent characters in pattern-value.

Examples are:
� address.phone LIKE �12%3� is true for �123� �12993� and false for �1234�
� asentence.word LIKE �l_se� is true for �lose� and false for �loose�
� aword.underscored LIKE �\_%� ESCAPE �\� is true for �_foo� and false for �bar�
� address.phone NOT LIKE �12%3� is false for �123� and �12993� and true for �1234�
If the value of the single_valued_path_expression is NULL, the value of the LIKE expression is
unknown.


This takes me back to the dark days of reading the JCA specs for the first time <shudder>
 
Scott Selikoff
author
Bartender
Posts: 4087
21
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, I thought it was the "LIKE" clause you were talking about, but yeah "LIKE" with input parameters... seems like it should be included as part of 11.2.7.9, but it does say "string literals only". This is a good example of why no one likes the EJB2 spec, especially for for entity beans.
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Scott Selikoff:
Ah, I thought it was the "LIKE" clause you were talking about, but yeah "LIKE" with input parameters... seems like it should be included as part of 11.2.7.9, but it does say "string literals only". This is a good example of why no one likes the EJB2 spec, especially for for entity beans.


Apologies for that, looking at my one line answer above I definitely should have made that clearer. Also apologies if I seemed to keep belabouring the point, it's just that it was the interesting topic I saw today!

Edit: Sorry all for my sig, I've obviously got the UBBcode wrong, will try to fix it ASAP!

[ September 01, 2008: Message edited by: Martijn Verburg ]
[ September 01, 2008: Message edited by: Martijn Verburg ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!