-->
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.  [ 3 posts ] 
Author Message
 Post subject: Using User Defined SQL Functions on fld while updating
PostPosted: Tue Sep 13, 2005 7:01 am 
Newbie

Joined: Tue Aug 30, 2005 4:04 am
Posts: 7
Hi All,

I have just started to work with Hibernate and I am using it with Spring MVC framework. My problem is that I need to use a user defined SQL function when updating the password. Now I have no idea how can I do this while using Hibernate version:3

aTaxPayerAccount = (TaxPayerAccount)this.getHibernateTemplate().get(TaxPayerAccount.class, user_id);
aTaxPayerAccount.setPassword("dbo.EncMe("+password+")");
aTaxPayerAccount.setReset_flg("Y");
this.getHibernateTemplate().update(aTaxPayerAccount);


Error stack trace of the exception:
org.springframework.dao.DataIntegrityViolationException: Hibernate operation: co
uld not update: [com.etax.admin.resetpassword.model.TaxPayerAccount#Harsh]; SQL
[update T_USER_PROFILE set password=?, hintQuestion=?, hintAnswer=?, email=?, re
set_flg=? where userid=?]; [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer
]String or binary data would be truncated.; nested exception is java.sql.SQLExce
ption: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]String or binary da
ta would be truncated.
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Str
ing or binary data would be truncated.


Name database :SQL SERVER 2000. jdbc.microsoft.sqlserver driver


I would appreciate all your inputs. Thanks!

Regards,
Harsh


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 13, 2005 7:05 am 
Newbie

Joined: Tue Aug 30, 2005 4:04 am
Posts: 7
I think the simplest of all would be to use the SQL directly instead of HQL. But I am sure that would be something better than this. I would keep this as my last option, unless there is anything else that can be done.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 15, 2005 2:59 am 
Newbie

Joined: Tue Aug 30, 2005 4:04 am
Posts: 7
Hi All,

I want to use a User defined SQL Procedure while updating a fld but have no clue how to do that. Following is the description of my problem statement:

I want to update a user's password. But before writing it in the DB, want to encrypt it. This encryption is done using a SQL Procedure. So tried:

Code:
String strResult = (String) this.getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(Session session)
throws HibernateException {
SQLQuery query = session.createSQLQuery(
"update T_TAXPAYER_ACCOUNT set password=dbo.EncMe(" + password
+ "), reset_flg='Y' where userid='"+user_id+"'");
int iReturn = query.executeUpdate();
return iReturn + "";
}
});


where dbo.EncMe is that SQL Procedure. This gives the UnsupportedOperationException exception.


I tried another (funny) way:

Code:
aTaxPayerAccount = (TaxPayerAccount)this.getHibernateTemplate().get(
TaxPayerAccount.class, user_id);
aTaxPayerAccount.setPassword("dbo.EncMe("+password+")");
aTaxPayerAccount.setReset_flg("Y");
this.getHibernateTemplate().update(aTaxPayerAccount);


and it sure didn't work. Can anyone please suggest me how to get this done. I hope I was able to make my problem statement clear.

I would appreciate all inputs.

Thanks!!


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