Hi Friends!
I am new to hibernate. now i am working in hibernate enhancement project. For this project we are using MyEclipse 5.5 and MySQL 5.0.
where i am using HQL queries to retrieve data from mysql database.
the code like as
Code:
public String[] checkSecurityCode(String code){
String[] result = new String[8];
BaseHibernateDAO dao=null;
try {
dao= new BaseHibernateDAO();
session =dao.getSession();
txt=session.beginTransaction();
Iterator results =session.createQuery("from Users u where u.username='admin'").iterate();
if(results.hasNext()) {
Users u=(Users)results.next();
String uid =u.getUserId().toString();
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(code.getBytes());
String encodedCode = new String(Base64.encode(md.digest()));
String encodedDbSecurityCode = u.getSecurityCode();
if(!encodedDbSecurityCode.equals(encodedCode)) {
result[0] = "<b>Sorry!</b> Incorrect security code.";
}
else if(encodedDbSecurityCode.equals(encodedCode)) {
result[0] = "Success";
result[1] = uid;
result[2] = u.getDashFlag();
result[3] = u.getUserGroup().toString();
result[4] = u.getUserRole();
long nextPasswordChange = u.getNextPasswordChange();
boolean changePwd = new Date().getTime() >= nextPasswordChange;
result[5] = Boolean.toString(changePwd);
result[6] = u.getHasMessage().toString();
result[7] = u.getLastLogin().toString();
new Update().setUserValidLogin(uid, session);
}
}
}
catch (Exception e) {
System.out.println("Exception in Retrieve > checkSecurityCode: " + e.getMessage());
result[0] = "Sorry! There was a problem while processing your request.";
}
finally{
txt.commit();
session.close();
}
return result;
}
But it's very slow when compared to native JDBC code.
Could anyone guide me to improve fetching performance and techniques to tuning MySQL DB for hibernate. How to write better hibernate code for insert, retrieve, update and delete operations for my project. In our project we are just converting all SQL queries to HQL queries, just all.
If u know any books and articles for hibernate tuning for MySQL 5.0 for better performance.It's very helpful to me and team. Becaz our project is real time project, going to process thousand of thousands data in a second. So plz provide me some help, it's very urgent.Thanks in advance.