aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes EJB-QL question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "EJB-QL question" Watch "EJB-QL question" New topic
Author

EJB-QL question

Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2851
    
  11

I'm using EJB 2.1. I want to write a query that returns objects matching an Integer parameter, but if the passed in parameter is null, returns objects with null in that field. Something like:


The only problem is "?1 IS NULL" is illegal. Is there any other way I can do it, or do I have to write two different queries?
Sunil Dixit
Ranch Hand

Joined: Sep 22, 2005
Posts: 46
Hi Greg,
You can't make run time check or can't make use of EQL functions to evaluate EJB QL parameters i.e. parameters those are passed to finder methods as arguments.
Actually it does not make sence coz objective of EQL is to reterive the data from database as per EQL , not to perform any type of check on finder method's parametrs.
These check should me performed perior to calling the finder method.
So method which is calling that finder method has to make this check.
SO you need to create to finders

1. SELECT OBJECT(o) from MyTable WHERE o.myField = ?1

2. SELECT OBJECT(o) from MyTable WHERE o.myField IS NULL

call finder 1 when the passed parameter is not null otherwise call finder 2

Thnaks
Sunil Dixit
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2851
    
  11

Thanks Sunil. It makes some sense, but in my case myField is a unique key, which could be null or an integer. It would be nice to be able to retrieve the record with that unique key in a single query. If it's not possible though, then it's not possible.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: EJB-QL question