Skip to Main Content

Java Development Tools

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

EJB QL issues using sql functions in EJB QL statement

HDGeekMay 6 2015 — edited May 6 2015

I am trying to convert this sql statement to ejb ql so I can pass it into the createQuery method of an entity manager

select nvl(max(1),0)

        from PayPeriods        where to_char(sysdate,'mm') = '01'

         and to_char(endpayperiod,'mm') = '01'

         and to_char(endpayperiod,'dd') <= '14';

Here is my code:

        String queryPayPeriods= "select nvl(max(1),0) from PayPeriods o where to_char(sysdate, 'mm') = '01' and to_char(o.endPayPeriod, 'mm') = '01' and to_char (o.endPayPeriod, 'dd') <= '14'";

        long payperiodCount = (Long)(em.createQuery(queryPayPeriods).getSingleResult());

I get this error:

The SELECT clause has 'nvl' and '(MAX(1), 0)' that are not separated by a comma.

The expression is not a valid conditional expression.

If I use this ejb ql statement, "select count(o.endPayPeriod) from PayPeriods o where to_char(sysdate, 'mm') = '01'and to_char(o.endPayPeriod, 'mm') = '01' and to_char (o.endPayPeriod, 'dd') <= '14'", then I get this error:

The expression is not a valid conditional expression.

If I omit the where clause and use "select count(o.endPayPeriod) from PayPeriods o", then it runs successfully but the result set isn't correct without the where clause. So evidently EJB QL does not like the nvl(mad(1),0) nor does it like my where clause!

I am developing in JDeveloper 12c, and am using EJB 3.0 in this particular application. Can you please tell me or direct me to a resource that can help me achieve my goal?

Thanks

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 3 2015
Added on May 6 2015
0 comments
585 views