0

When I run the following SQL query in Hibernate I got org.hibernate.exception.GenericJDBCException: could not execute query:

select cast(DECRYPTBYKEY(cc.EncryptCardno) as varchar(30)) as cardNo 
from stmtOfAccounts s, creditCards cc 
where s.creditCardId = cc.id and s.id = :stmtOfAccountId

This is the HQL:

String hqlQuery = String.format(
  "select cast(DECRYPTBYKEY(cc.EncryptCardno) as varchar(30)) as cardNo " +
  "from stmtOfAccounts s, creditCards cc " +
  "where s.creditCardId = cc.id and s.id = :stmtOfAccountId");
nobeh
  • 9,784
  • 10
  • 49
  • 66
sudo
  • 1,525
  • 7
  • 34
  • 59
  • 1
    What makes you think that `cast()` and `DECRYPTBYKEY()` are HQL functions? – Matt Ball Jul 31 '12 at 03:00
  • hi i need to get decrypt data but don't know how to use – sudo Jul 31 '12 at 03:03
  • You said "run the following SQL Query" but later you said "This is the HQL", what are you running? SQL or HQL? – Adrian Shum Jul 31 '12 at 03:05
  • actually i use spring and hibernate for this application and i run native sql in this application. The first sql statement is I got after i executed the second hql query. – sudo Jul 31 '12 at 03:14
  • 1
    why are you exeucte HQL query when you are saying you want to run native SQL in your app? Have you tried to run the SQL manually (using some SQL client of the DBMS you are using) ? – Adrian Shum Jul 31 '12 at 03:30
  • hi Adrian , now I got another exception com.microsoft.sqlserver.jdbc.SQLServerException: The column name id is not valid. – sudo Jul 31 '12 at 03:49

0 Answers0