-->
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.  [ 10 posts ] 
Author Message
 Post subject: How to use database functions on insert/update
PostPosted: Sat Sep 06, 2003 12:38 am 
Newbie

Joined: Tue Aug 26, 2003 9:59 am
Posts: 19
Location: Atlanta, GA
I would like to apply a database function to a column value when the value is inserted or updated. In particular, I want to apply the MySQL SHA function to hash the users password prior to its storage - I would roughly like the following SQL to occur:
Code:
update users set values (?,SHA(?),...) where user.id=?

What I would use the new "formula" property attribute for this? If so, is the formula applied on both storage and retrieval? Can an example be provided? Currently, I am able to use the function when selecting values as in the following HQL:
Code:
select usr from eg.Users usr where usr.username=? and usr.password=SHA(?)

I pre-apologize if this has alreay been answered :)

_________________
Bill Siggelkow


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 06, 2003 12:44 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
The formula is applied on storage.

If you want to apply a SQL function, use a trigger.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 06, 2003 12:44 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
uggh

The formula is NOT applied on storage.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 06, 2003 12:47 am 
Newbie

Joined: Tue Aug 26, 2003 9:59 am
Posts: 19
Location: Atlanta, GA
Hmm looking at the road map document maybe I thought I could do something like:
Code:
<property name="hashedPassword" formula="SHA(passwd)"/>

However, this not what I want -- by design, I cannot unhash the value -- still thinking ... maybe native SQL statement?

_________________
Bill Siggelkow


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 06, 2003 12:49 am 
Newbie

Joined: Tue Aug 26, 2003 9:59 am
Posts: 19
Location: Atlanta, GA
Arghh -- AFAIK MySQL doesn't support triggers :( Anyway, I will look into other options -- thanks for the quick response.

_________________
Bill Siggelkow


Top
 Profile  
 
 Post subject: Has this been solved yet?
PostPosted: Fri Oct 24, 2003 9:31 pm 
Newbie

Joined: Fri Oct 24, 2003 9:23 pm
Posts: 10
I am wondering if this problem has a solution. I too want to use a native MySQL function (md5) for password encryption.


thanks in advance,
-j


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 24, 2003 11:05 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Perhaps its a case for a custom persister.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 25, 2003 12:49 am 
Newbie

Joined: Fri Oct 24, 2003 9:23 pm
Posts: 10
I assume that would be by extending EntityPersister?

-jp


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 02, 2008 7:17 pm 
Newbie

Joined: Mon Jun 02, 2008 7:14 pm
Posts: 1
is there an answer to this?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 03, 2008 2:19 am 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
Yes i agree that’s the problem with hibernate. I faced while same issue with pass code encryption and decryption .For retrieval you could use function in HBM files. But if you want to encrypt while insert or update I would suggest, try to implement those logic in setter and getter not sure .I guess that would work. That is not very good solution for them who has good background of DBA or for legacy system.

Any way another way we could think to this same is write these logic in our own extend class of public class AuditLogInterceptor implements Interceptor is which use to intercept save update and on load .I don’t know how efficient it would be .Try it that won’t take too much time
http://www.hibernate.org/318.html

_________________
Dharmendra Pandey


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 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.