• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to use DB2 decrypt_char() with Hibernate

 
siddartha kandikonda
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • 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




 
Rishi Shehrawat
Ranch Hand
Posts: 218
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • 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
  • 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 Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What was the workaround?
 
siddartha kandikonda
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic