david wrote:
Think in terms of an array list so in that context the index refers to the positon in the data structure (thus nothing to do with database indexes).
So let me get this straight.. index tag in hbm.xml has nothing to do with database indexes??
Then, my next question is
"is there any way to implement database indexes to speed up performance in Hibernate?"Here is the case, I've built a project in Hibernate.. when the transaction is still below 1000, the speed is quite fast. But later, the speed is quite slow, that I have to restart tomcat few times each week. I'm using Hibernate 2.1.2, Tomcat 4.1.29 and Tapestry 3.
My GetUser would look like this :
public class GetUser
{
private List usrList = null;
private User theUser = null;
public GetUser()
{
sessFact = ConfigTimeAwal.getSessionFactory();
try {
if (sessFact==null)
{
configure();
System.out.println("AT CONFIGURING CONSTRUCTOR");
listAll();
}
} catch (HibernateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public User byUserName(String name) throws HibernateException {
System.out.println("Retrieving the User");
sess = sessFact.openSession();
//Transaction tx = null;
try
{
//tx = sess.beginTransaction();
/*Start Query*/
String query =
"select usr from User as usr "
+ "where lower(usr.userName)=lower(:name)";
usrList = sess.find(query, name,Hibernate.STRING);
/*End Query*/
if (usrList.size() == 0)
{
System.out.println("No user named " + name);
return null;
}
else
{
theUser = (User)usrList.get(0);
System.out.println(theUser);
System.out.println("User is successfully retrieved");
}
//tx.commit();
}
catch(HibernateException he)
{
//if(tx!=null) tx.rollback();
throw he;
}
finally
{
sess.close();
}
return theUser;
}
}
So
whenever I call GetUser, I always create an object (since I'm not using static methods) , does it really affect the performance badly??
david wrote:
If you indexes to the data structure has gaps eg a index sequence like 0,1,3
this would result in array list of 4 element where a null will be at index position 2.
So if I use List instead of Set for non-unique transaction, it will be undeniably faster??
Sorry for the silly question, but I'm new in Hibernate here.