-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: How to use DB2's encrypt in Hibernate
PostPosted: Sat May 17, 2008 12:41 am 
Newbie

Joined: Sat May 17, 2008 12:35 am
Posts: 1
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:3.2

Based on my current case, we wanna to encrypt some fields in DB2 using DB2's encryption method, the SQL I should use is likes below:

create table emp (ssn varchar(124) for bit data);
set encryption password = 'Ben123';
insert into emp (ssn) values(encrypt('289-46-8832'));
insert into emp (ssn) values(encrypt('222-46-1904'));
insert into emp (ssn) values(encrypt('765-23-3221'));
select decrypt_char(ssn) from emp;

And then, when we are construct the mapping in Hibernate, we want the Hibernate to complete the work on appending encrypt/decrypt before the ssn in SQL likes before. What can I select/insert/update the emp object from Hibernate for this kind of records?

Anybody can help me?


Top
 Profile  
 
 Post subject: Re: How to use DB2's encrypt in Hibernate
PostPosted: Mon Aug 02, 2010 10:42 pm 
Newbie

Joined: Mon Aug 02, 2010 10:19 pm
Posts: 2
Location: Duluth,GA
It can be done,its just a little tricky though,there is a problem with Hibernate and DB2-VARCHAR FOR BIT DATA data type which is recommended for encrypted columns,the save() function did not work for me,the only way i got it right was to
1.set the insert="false" update="true" for the encrypted column in the class mapping
2.Insert data into the rest of the columns using save()
3.Update the encrypted column separately using a Named SQL ,something like this
UPDATE <table-name>
SET = encrypt(CAST(:xxxxxx AS VARCHAR(7)))
WHERE <column-name> = :XXXXX


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.