Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

hibernate - need to encrypt before going to db

 
peter cooke
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello - New to hibernate and trying to wrap my head around.

I have an existing app that uses hibernate to put data into and out of a data base. I have many classes that call the my particular hibernate object. ( sorry still leanring proper terms). My new requirement is to encrypt one column in the db table. rather than change all the pieces of code that call my hibernate persistant object.

I want my one hibernate object to do the encryption/decryption for me.

Can someone point me in the right direction to do that.
I have the relatively new Baur-King "Java Persistance with Hibernate" book.

I tried modifying the setters and getters in the dto that hibernate uses. But it encrypted the value only while in the DTO. the unencrypted form was still being set in the db.

I think this should be relatively easy.
Peter
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can create a custom UserType, most likely a CompositeUserType to be able to query on the attributes.

This will allow you to write how you load and write to the database, so in there is where you would encrypt and decrypt

Here is one example
http://www.hibernate.org/169.html

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic