-->
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: Hibernate sessions and transactions issue
PostPosted: Tue Apr 25, 2006 6:54 pm 
Newbie

Joined: Fri Sep 02, 2005 3:51 pm
Posts: 17
Hi,
I am using Hibernate with Spring for a web based application running on Tomcat5.
I have a table called CreditCard which stores credit card information. CCTransactionDAO class uses hibernate to access a MySQL database.

A ccTransactionManager interface is used to call the CCTransactioDAO to get and save rown in the table.
All configuration is performed using spring's applicationContext.xml
Show below is the ccTransactionManager bean creation in the applicationContext.xml

What I am trying to do is this: When a method called getCreditCard(customerId) is invoked on the manager, before returning the CreditCard object, I need to decrypt it. So I call a decrypt(CreditCard) method within the getCreditCard(customerId) method. The decrypt(CreditCard) method is a private method in the manager. code shown below.
But when I call the decrypt method, the decrypted values are written to the database (to the row corresponding to the CreditCard object returned by the getCreditCard method. I am guessing this is because the session is still active under the transaction created for the manager.
I would like to decrypt the card info without writing the decrypted value to the db.

I hope this is not too confusing, and any help will be greatly appreciated.

thanks,
-Riz.
-------------------------------------------------------------------------------------
<bean id="ccTransactionManager"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref local="transactionManager"/>
</property>
<property name="target">
<ref local="ccTransactionManagerTarget"/>
</property>
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>

<bean id="ccTransactionManagerTarget"
class="com.cwsi.eshipper.service.impl.CCTransactionManagerImpl">
<property name="CCTransactionDAO">
<ref local="ccTransactionDAO"/>
</property>
</bean>

-------------------------------------------------------------------------------------

methods in ccTransactionManager

public CreditCard getCreditCardByCustomerId(long customerId){

CreditCard cc = dao.getCreditCardByCustomerId(customerId);
if(cc==null)
return null;
//decrypt the card info first
decryptCCData(cc);

return cc;
}

private void decryptCCData(CreditCard cc){
try{
String decrypted_ccNum = CryptoFactory.getCrypto().decryptFromBase64Encoded(cc.getCcNumber());
String decrypted_ccExpMonth = CryptoFactory.getCrypto().decryptFromBase64Encoded(cc.getCcExpiryMonth());
String decrypted_ccExpYear = CryptoFactory.getCrypto().decryptFromBase64Encoded(cc.getCcExpiryYear());
cc.setCcNumber(decrypted_ccNum);
cc.setCcExpiryMonth(decrypted_ccExpMonth);
cc.setCcExpiryYear(decrypted_ccExpYear);
}
catch(Exception e){
logger.debug("Unable to decrypt credit card information!");
e.printStackTrace();
throw new CryptoException(e.getMessage());
}


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 25, 2006 10:33 pm 
Regular
Regular

Joined: Wed Jul 07, 2004 2:00 pm
Posts: 64
You could evict the credit card from the Hibernate session in the DAO (session.evict(cc)), or you could clone the cc in the manager, decrypt the clone and return that cc.


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.