Anand
Anand

Reputation: 1841

JPA Native Query

I am trying to execute a native query and pass run-time parameters and get the result as a List. When I try to process the Object [], one of the columns fetched is a String. But it comes out as java.lang.Character instead of String. Here is the query below:

SELECT CASE
         WHEN (TRUNC(abm.credit_card_expiration_date) BETWEEN trunc(SYSDATE) AND
              trunc(last_day(SYSDATE))) THEN
          'Expires'
         ELSE
          'Expired'
       END EXP_STATUS,
       TO_CHAR(abm.credit_card_expiration_date, 'MM/YY') EXP_DATE
  FROM account_billing_methods abm
 WHERE abm.account_id = 201103
   AND abm.billing_type_id = 1
   AND TRUNC(abm.credit_card_expiration_date) <= TRUNC(LAST_DAY(SYSDATE))

The EXP_STATUS column could not be typecasted into String as it is of type Character. Any ideas of why it does not work?

Regards, -Anand

Upvotes: 0

Views: 2434

Answers (1)

MArKiTo
MArKiTo

Reputation: 11

I had the same problem and changed the select clause of my query to: EXP_STATUS || '' as EXP_STATUS

Then it is a VARCHAR instead of a CHAR and JPA will return it as a String instead of a Character.

If someone knows a better/more elegant solution, I would appreciate if you could share it.

Upvotes: 1

Related Questions