Question

This is the problem asked to me by one of my seniors.

1) We have two different nodes of a J2EE Application Server : Node 1 and Node 2. (As shown in the image below.)

2) Also hibernate second level cache is being enabled.

3) Problem is as follows: A User hits the login page URL and assume that this request goes to Node 1 and User Logs in and then User Logs Out.

4) Again User request for Login page and this time, request goes to Node 2. Now User logs in and changes his password and Logs out.

Now the Question is when user tries to login with his new password and request goes to Node 1. Will he be able to login into the system ?

If he is not able to do it, what could be done to make user login with his new password on Node 1.

Note: We have a LoginUser table where the Username and passwords are stored. 

enter image description here

My Answer :

As per my opinion, it could be the case that when User tries to login using Node 1 and then logs out.

Hibernate fires this query:

select * from Login where username = "John";

And this entry is cached in the second level cache of node 1.

Now when he logs in into the system using Node 2 and changes his password. And again tries to login to Node 1, he is not able to log in using his new password, because this time Second level cache of node 1 is containing the old password, So he can login using his old password.

This is the reason why he is not able to login to node 1 with new password.

Now the solution of this problem could be the replication of second level cache.

Kindly share your inputs on the same problem.

Was it helpful?

Solution

The answer to your problem is a distributed second level cache as described in the Hibernate documentation here. Infinispan is the best supported platform. You can read about setting this up on the Jboss wiki.

This will take care of invalidating the 2LC across the cluster when cached data changes on either node. The node the users requests hits will then know that the cache is stale and will go to the database to load the required fresh data.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top