-->
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.  [ 5 posts ] 
Author Message
 Post subject: The Use OF List
PostPosted: Wed Jun 30, 2004 7:36 am 
Beginner
Beginner

Joined: Wed Feb 25, 2004 5:54 am
Posts: 30
I see that we need to use List in order to have the index column... my question is,

1. AFAIK, index is used to speed up data retrieval....The index here, does it have the same purpose?

2. To implement index correctly, how do I implement the index? Do I insert a different value for each insert or does it have some specific rule...?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 30, 2004 7:30 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
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).

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.


Top
 Profile  
 
 Post subject: thanks, but..
PostPosted: Thu Jul 01, 2004 12:54 am 
Beginner
Beginner

Joined: Wed Feb 25, 2004 5:54 am
Posts: 30
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.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 01, 2004 5:37 am 
Beginner
Beginner

Joined: Wed Feb 25, 2004 5:54 am
Posts: 30
Can anyone please tellme how to speed up performance and how to implement List in Select and Insert new record???


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 01, 2004 1:49 pm 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
execute "CREATE UNIQUE INDEX user_name ON user (name)" command to create index on database and drop "lower" in query, store user name as lowercase string (do it at object create time)

Code:
String query =
"select usr from User as usr "
+ "where usr.userName = lower(:name)";
usrList = sess.find(query, name,Hibernate.STRING);


You can use "EXPLAIN" (depends on RDBMS implementation) command to see query plan, if you will find "index scan" in trace, it means optimizer uses index and response time will not depend on table size.


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

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.