LIKE operator in EJB-QL


EJB programming & troubleshooting: LIKE operator in EJB-QL

  1. LIKE operator in EJB-QL (5 messages)

    Can anyone tell me how can we use parameter in the comparison pattern for LIKE operator.

    For e.g.

    select Oject(a) from product a where LIKE 'A%'

    works fine but how can we use it

    select Oject(a) from product a where LIKE %?1%

    where ?1 is parameter from finder function

    Help from anyone is highly appreciated

    Threaded Messages (5)

  2. LIKE operator in EJB-QL[ Go to top ]

    Parameters are not permitted bye EJB specification the LIKE operator.

    This is because many times it is convenient to write session beans to perform searches throught JBDC direct calls (ORDER BY is another).
  3. Thanks for your reply[ Go to top ]

    Thanks for your reply
  4. Chose your spec or app.server[ Go to top ]

    Have been playing around with this myself some time ago.

    First, a short look at the EJB specifications:

    EJB 2.0: Section Like expresions :

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

    The pattern-value is a string literal ......

    EJB 2.1: Section Like expressions :

    cmp_path_expression [NOT] LIKE pattern_value [ESCAPE escape_character]

    The pattern_value is a string literal or a string-valued
    input parameter....

    The important difference here is the addition of string-valued input parameter to the definition of pattern_value.

    It was a while ago, but if I remember correct IBM WebSphere (don't remember if it was only v5 or also v4) will allow you to use string-valued input parameters in the like clause (I think this is mentioned in the documentation as an IBM extension) (disclaimer, work for IBM, don't speak for them).
    I think it was also possible in JBoss to get something like this. It required a special jboss deployment file in your EJB jar, which had and jboss-ql entry or something.

  5. Thanks Jonas[ Go to top ]

    Thanks Jonas
  6. LIKE operator in EJB-QL[ Go to top ]

    as following not allowed in EJBQL

    select Oject(a) from product a where LIKE %?1%

    but we can appened % sign to both side of the parameter before calling that particular function and it works. e.g

    name = "%"+name +"%";

    findByName(String name){
    select Oject(a) from product a where LIKE ?1