-->
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.  [ 1 post ] 
Author Message
 Post subject: Hibernate cache problem
PostPosted: Tue Oct 27, 2009 7:54 am 
Newbie

Joined: Tue Jun 09, 2009 7:54 am
Posts: 10
Hi all,

I am facing the following issue:
I have a piece of code for authenticating a user and another for updating his password.
Consider the following steps:
1) A user tries to authenticate himself - he can login successfully
2) The user updates his password. It gets updated successfully in the DB
3) The user tries authenticating himself again and can login with the new password.
4) Now, I manually update the password in the database. If the user tries to use this new password to authenticate himself, he is unable to do so. This is because, in the authentication code below, the password fetched from the DB is the same as the one fetched in step number (3).

It seems as though the old password used by the user is stored in the cache and is reused the next time the user tries to authenticate himself. I have tried making the following 3 settings, so that no information is fetched or stored in the cache. But it does not seem to be working.
Code:
session.setCacheMode(CacheMode.REFRESH);
sessionFactory.evictQueries();

query.setCacheable(false);




Authentication code
Code:
public void authenticate (String ePwd) {
File f = new File("C:\\hibernate-config.xml");
Configuration config = new Configuration();
Configuration configuration  = config.configure(f);
sessionFactory = configuration.buildSessionFactory();
Session session = sessionFactory.openSession();      
session.setCacheMode(CacheMode.REFRESH);
sessionFactory.evictQueries();

String SQL_QUERY = "select username, project, password from User where username like '" + username + "'))";
   
Query query = session.createQuery(SQL_QUERY);
query.setCacheable(false);

User user = null;
try {
   for(Iterator<Object[]> it=query.iterate();it.hasNext();){         
   Object[] row = (Object[]) it.next();      
   String pwd = (String)row[2];
   System.out.println("User entered: " + ePwd + " Password fetched from DB: " + pwd);
}
finally {
   session.flush();
   session.clear();
   session.close();
}

}



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

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.