Forums Register Login

Optional parameters in EJB QL?

+Pie Number of slices to send: Send
Hello,
I'm trying to create a finder in a container-managed EJB, with optional parameters. What do I mean? Well, I'm looking for certain data in my tables which occur within a certain date interval. I would like to use a single method for this:
findDataInInterval(Integer type, Date occursAfterThisDate, Date occursBeforeThisDate)
Which can conceivably generate at least 4 SQL queries (using a EJB-QL'ish syntax):
select * from my table where type = ?type
select * from my table where type = ?type and mydate > ?occursAfterThisDate
select * from my table where type = ?type and mydate < ?occursBeforeThisDate
select * from my table where type = ?type and mydate > ?occursAfterThisDate and mydate < ?occursBeforeThisDate
Is there a way to generalise the four queries into one entry, so that the mydate clauses are ignored if either (or both) dates are null?
Thanks,
L
+Pie Number of slices to send: Send
Hi Laurent,
Those look like four different custom finders to me.
Regards,
Eat that pie! EAT IT! Now read this tiny ad. READ IT!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 977 times.
Similar Threads
clicking on text retrieve data from database
Oracle cast()+PreparedStatement
why we can set String to date ?
CMP 2.0 problem in Jboss 4.0.2
Handling Dates in JSP + Beans
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 12:25:43.