• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to use DB2 decrypt_char() with Hibernate

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have DB2 table which has a column holding encrypted passwords of data type VARCHAR FOR BIT DATA
i am able to store the password in this column using DB2 encrypt() function,so far so good,the trouble is when i try to read that password back using DB2 decrypt_char()
function,i am trying to do that using a Named Native SQL Query like the one below

SELECT decrypt_char(TEMP_PASSWORD)
FROM <table name>
WHERE LCASE(USER_EMAIL_ADDRESS) = :emailId

this gives me an exception and i am only posting the lines that are significant from the stack trace

Caused by: org.hibernate.exception.GenericJDBCException: could not execute query
Caused by: com.ibm.db2.jcc.b.SqlException: [ibm][db2][jcc][10150][10300] Invalid parameter: Unknown column name TEMP_PASSWORD.

i dont understand why,because not only is the column in present in the table but also the mapping is perfect in the hbm.xml
btw i am using a JDBC Type 4 driver and DB2 V9

any help would be great




 
Ranch Hand
Posts: 218
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The exception seems to be thrown by DB2, rather than Hibernate so i would suspect issue with SQL. It seems very obvious & in all probability you would have tried this but i will still ask - Were you able to execute query from SQL prompt?
 
siddartha kandikonda
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes it works from the console,its in fact a pretty straight forward SQL,but somehow dosen't work with Hibernate,all i can say that Hibernate has got a problem handling VARCHAR FOR BIT DATA fields in DB2,the problem may be with the type of JDBC driver too,anyways i found a workaround for this problem after a few ruined weekends:-)
 
Rishi Shehrawat
Ranch Hand
Posts: 218
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What was the workaround?
 
siddartha kandikonda
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well,my requirement was to decrypt the password to check if it matches what the user enters,since i was not able to do that,i get the encrypted form of the password user enters and compare it to the value in the table,this way i don't have to deal with the decrypting stuff,not a great idea but it works
reply
    Bookmark Topic Watch Topic
  • New Topic