I just went through this article and this which I found will improve the performance of my application as it had 99% read operations only. I implemented it in test application first just to test it(referred this) , though I am getting the result but as per the second link i mentioned, if the query is same for same parameter value, db hit will take place but on the basis of primary key of relation.
Classes are mentioned below:
Entity Class
@Entity(name="User_Details")
public class UserDetails {
@Id
private String userName;
private String password;
private String name;
private Long msisdn;
//getter and setter are in place//
}
DAO Class
public class UserDetailsDAOImpl {

SessionFactory sessionFactory;

public UserDetailsDAOImpl() {
sessionFactory = new Configuration().configure().buildSessionFactory();
}

public UserDetails getUser(String param1) {
Session session = sessionFactory.openSession();
System.out.println("session : " + session);
session.beginTransaction();
Criteria query = session.createCriteria(UserDetails.class).add(Rest rictions.eq("name",param1));
UserDetails dummy_user=(UserDetails) query.setCacheable(true).uniqueResult();
session.close();
return dummy_user;
}
Main Class
UserDetailsDAOImpl obj=new UserDetailsDAOImpl();
UserDetails response = obj.getUser("Borat16");
System.out.println("Test:"+response);
UserDetails response1 = obj.getUser("Borat16");
System.out.println("Test1:"+response1);
Hibernate.cfg.xml

true


org.hibernate.cache.EhCacheProvider

true

update
// First Query Result : As per the article first time it will hit the db (as expected)
Hibernate: select this_.userName as userName1_0_0_, this_.msisdn as msisdn2_0_0_, this_.name as name3_0_0_, this_.password as password4_0_0_ from User_Details this_ where this_.name=?
Test:UserDetails [userName=ak416, password=magnum16, name=Borat16, msisdn=116]
// Second Query Result : Now since the query is same and same parameter why the sql statement generated is not looking like "select * from user_details where userName='ak47'. I mean it should hit db with where parameter as key . What I am missing ?!
Hibernate: select this_.userName as userName1_0_0_, this_.msisdn as msisdn2_0_0_, this_.name as name3_0_0_, this_.password as password4_0_0_ from User_Details this_ where this_.name=?
Test1:UserDetails [userName=ak416, password=magnum16, name=Borat16, msisdn=116]


Check Solution