I'm using hibernate but I'm facing a performance problem with it!
When I use it on a local database it's extremely fast but very slow on a remoted database (and by remoted database I mean in a local network)!!
Why?!!
I know you will say maybe it's a lazy loading problem but I have tested it on simple select for one entity (without children) but still slow, check this out:
public List<Employee> read() {
List<Employee> objects = null;
Transaction tx = null;
try {
tx = HibernateUtil.SESSION.beginTransaction();
Long start = System.currentTimeMillis();
objects = HibernateUtil.SESSION.createQuery("FROM Employee AS T ORDER BY T.id DESC").list();
Long stop = System.currentTimeMillis();
System.out.println( "Time: " + (stop - start) + "ms." );
tx.commit();
} catch (HibernateException e) {
if (tx != null)
tx.rollback();
e.printStackTrace();
}
return objects;
}
As you can see a simple select query and this is the result I get:
Locally: 31ms
Remotely: 356ms !!!!
And this is my config file:
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.username">postgres</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.connection.url">jdbc:postgresql://192.168.1.3:5432/my_database</property>
<property name="connection_pool_size">1</property>
<property name="hbm2ddl.auto">update</property>
<property name="show_sql">false</property>
<property name="hibernate.enable_lazy_load_no_trans">true</property>
</session-factory>
</hibernate-configuration>
Can you explain this ?