-->
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.  [ 2 posts ] 
Author Message
 Post subject: problem with hibernate query performance
PostPosted: Mon Dec 18, 2006 7:51 am 
Newbie

Joined: Mon Dec 18, 2006 6:49 am
Posts: 1
Hello everyone:)

I`m very new in hibernate and maybe my problem is very easy to solve
but i've spent several hours on searching google and other forums and nothing.
My application inserts data from xml file to PostgreSQL(version: 8.1.3) database and it takes over 4 minute for 1000 records. That's way I wrote
a simple example from "Hibernate in Action" to check a simple select query from my database (100 select querys). Unfortunately the resoults were the same: over 4sec.
When i use traditional jdbc connection method the performance is much better over 10 times (0,4sec). I have changed the jdbc drivers, hibernate.jar - no effect.
I know that i`m doing somthing wrong but i can`t find out what it is.
I will be very grateful for any help.

P.S.
In the main application i use Spring framework.
Hibernate version: Hibernate 3.2.1

Mapping documents:
hibernate.cfg.xml
<!DOCTYPE hibernate-configuration SYSTEM
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.url">jdbc:postgresql://**.***.***.**/bskd</property>
<property name="hibernate.connection.username">****</property>
<property name="hibernate.connection.password">**</property>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="hibernate.c3p0.minPoolSize">5</property>
<property name="hibernate.c3p0.maxPoolSize">20</property>
<property name="hibernate.c3p0.timeout">300</property>
<property name="hibernate.c3p0.max_statement">50</property>

<mapping resource="pl/net/kowalski/xmlData/Ticket.hbm.xml"/>

</session-factory>
</hibernate-configuration>

ticket.cfg.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping SYSTEM
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="pl.net.kowalski.bizness.Dane">
<class name="Ticket" table="ticket">
<id name="id_ticket" column="id_ticket" type="long">
</id>
<property name="id_kod_info" column="id_kod_info"></property>
<property name="kod_autoryzacji" column="kod_autoryzacji"></property>
<property name="liczba_wejsc" column="liczba_wejsc"></property>
<property name="waznosc_poczatek" column="waznosc_poczatek"></property>
<property name="waznosc_koniec" column="waznosc_koniec"></property>
<property name="nazwa_ticket" column="nazwa_ticket"></property>
<property name="bilet_rozszerzony" column="bilet_rozszerzony"></property>
<property name="id_rodzaj_ticketu" column="id_rodzaj_ticketu"></property>
<property name="id_imprezy" column="id_imprezy"></property>
<property name="id_klienta" column="id_klienta" not-null="false"></property>
<property name="id_sektor_naliczania" column="id_sektor_naliczania"></property>
<property name="state" column="state"></property>
<property name="row" column="row"></property>
<property name="number" column="number"></property>
<property name="bonus" column="bonus"></property>
<property name="extra" column="extra"></property>
<property name="print" column="print"></property>
<property name="abo" column="abo"></property>
<property name="work" column="work"></property>
<property name="card" column="card"></property>
<property name="type" column="type"></property>
<property name="idticket" column="idticket"></property>

</class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
public static void main(String[] args) {
SessionFactory sessionFactory = new Configuration().configure("WEB-INF/hibernate.cfg.xml").buildSessionFactory();

Session session = sessionFactory.openSession();
Transaction transaction = session.beginTransaction();
long startTime = System.currentTimeMillis();
for (int i = 0; i < 100; i++){
List l = session.createQuery("from Ticket where idticket ="+1290870).list();
}
System.out.println("Hibernate: "+((System.currentTimeMillis()-startTime)/1000.0f)+" sek");
transaction.commit();
session.close();

}
Full stack trace of any exception that occurs:

Name and version of the database you are using:
PostgreSQL(version: 8.1.3)
JDBC: postgresql-8.1-408.jdbc3
The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:
2006-12-18 12:18:13 org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.2.1
2006-12-18 12:18:14 org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
2006-12-18 12:18:14 org.hibernate.cfg.Environment buildBytecodeProvider
INFO: Bytecode provider name : cglib
2006-12-18 12:18:14 org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
2006-12-18 12:18:14 org.hibernate.cfg.Configuration configure
INFO: configuring from resource: WEB-INF/hibernate.cfg.xml
2006-12-18 12:18:14 org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: WEB-INF/hibernate.cfg.xml
2006-12-18 12:18:17 org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource : pl/net/kowalski/xmlData/Ticket.hbm.xml
2006-12-18 12:18:18 org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: pl.net.kowalski.bizness.Dane.Ticket -> ticket
2006-12-18 12:18:18 org.hibernate.cfg.Configuration doConfigure
INFO: Configured SessionFactory: null
2006-12-18 12:18:19 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Using Hibernate built-in connection pool (not for production use!)
2006-12-18 12:18:19 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 20
2006-12-18 12:18:19 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: autocommit mode: false
2006-12-18 12:18:19 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: org.postgresql.Driver at URL: jdbc:postgresql://***.***.***.**/bskd
2006-12-18 12:18:19 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=marcin, password=****}
2006-12-18 12:18:19 org.hibernate.cfg.SettingsFactory buildSettings
INFO: RDBMS: PostgreSQL, version: 8.1.3
2006-12-18 12:18:19 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC driver: PostgreSQL Native Driver, version: PostgreSQL 8.1 JDBC3 with SSL (build 408)
2006-12-18 12:18:19 org.hibernate.dialect.Dialect <init>
INFO: Using dialect: org.hibernate.dialect.PostgreSQLDialect
2006-12-18 12:18:19 org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
INFO: Using default transaction strategy (direct JDBC transactions)
2006-12-18 12:18:19 org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
2006-12-18 12:18:19 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic flush during beforeCompletion(): disabled
2006-12-18 12:18:19 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic session close at end of transaction: disabled
2006-12-18 12:18:19 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch size: 15
2006-12-18 12:18:19 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch updates for versioned data: disabled
2006-12-18 12:18:19 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Scrollable result sets: enabled
2006-12-18 12:18:19 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC3 getGeneratedKeys(): disabled
2006-12-18 12:18:19 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Connection release mode: auto
2006-12-18 12:18:19 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default batch fetch size: 1
2006-12-18 12:18:19 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Generate SQL with comments: disabled
2006-12-18 12:18:19 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL updates by primary key: disabled
2006-12-18 12:18:19 org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
2006-12-18 12:18:20 org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
INFO: Using ASTQueryTranslatorFactory
2006-12-18 12:18:20 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
2006-12-18 12:18:20 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JPA-QL strict compliance: disabled
2006-12-18 12:18:20 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Second-level cache: enabled
2006-12-18 12:18:20 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query cache: disabled
2006-12-18 12:18:20 org.hibernate.cfg.SettingsFactory createCacheProvider
INFO: Cache provider: org.hibernate.cache.NoCacheProvider
2006-12-18 12:18:20 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: disabled
2006-12-18 12:18:20 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Structured second-level cache entries: disabled
2006-12-18 12:18:20 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Statistics: disabled
2006-12-18 12:18:20 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Deleted entity synthetic identifier rollback: disabled
2006-12-18 12:18:20 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default entity-mode: pojo
2006-12-18 12:18:20 org.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
2006-12-18 12:18:21 org.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Not binding factory to JNDI, no JNDI name configured
Hibernate: 4.416 sek


Top
 Profile  
 
 Post subject: Re: problem with hibernate query performance
PostPosted: Wed Dec 20, 2006 4:12 am 
Newbie

Joined: Wed Dec 20, 2006 4:01 am
Posts: 1
meton wrote:
Hello everyone:)

I`m very new in hibernate and maybe my problem is very easy to solve
but i've spent several hours on searching google and other forums and nothing.
My application inserts data from xml file to PostgreSQL(version: 8.1.3) database and it takes over 4 minute for 1000 records. That's way I wrote
a simple example from "Hibernate in Action" to check a simple select query from my database (100 select querys). Unfortunately the resoults were the same: over 4sec.
When i use traditional jdbc connection method the performance is much better over 10 times (0,4sec). I have changed the jdbc drivers, hibernate.jar - no effect.
I know that i`m doing somthing wrong but i can`t find out what it is.
I will be very grateful for any help.

P.S.
In the main application i use Spring framework.
Hibernate version: Hibernate 3.2.1

Mapping documents:
hibernate.cfg.xml
<!DOCTYPE hibernate-configuration SYSTEM
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.url">jdbc:postgresql://**.***.***.**/bskd</property>
<property name="hibernate.connection.username">****</property>
<property name="hibernate.connection.password">**</property>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="hibernate.c3p0.minPoolSize">5</property>
<property name="hibernate.c3p0.maxPoolSize">20</property>
<property name="hibernate.c3p0.timeout">300</property>
<property name="hibernate.c3p0.max_statement">50</property>

<mapping resource="pl/net/kowalski/xmlData/Ticket.hbm.xml"/>

</session-factory>
</hibernate-configuration>

ticket.cfg.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping SYSTEM
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="pl.net.kowalski.bizness.Dane">
<class name="Ticket" table="ticket">
<id name="id_ticket" column="id_ticket" type="long">
</id>
<property name="id_kod_info" column="id_kod_info"></property>
<property name="kod_autoryzacji" column="kod_autoryzacji"></property>
<property name="liczba_wejsc" column="liczba_wejsc"></property>
<property name="waznosc_poczatek" column="waznosc_poczatek"></property>
<property name="waznosc_koniec" column="waznosc_koniec"></property>
<property name="nazwa_ticket" column="nazwa_ticket"></property>
<property name="bilet_rozszerzony" column="bilet_rozszerzony"></property>
<property name="id_rodzaj_ticketu" column="id_rodzaj_ticketu"></property>
<property name="id_imprezy" column="id_imprezy"></property>
<property name="id_klienta" column="id_klienta" not-null="false"></property>
<property name="id_sektor_naliczania" column="id_sektor_naliczania"></property>
<property name="state" column="state"></property>
<property name="row" column="row"></property>
<property name="number" column="number"></property>
<property name="bonus" column="bonus"></property>
<property name="extra" column="extra"></property>
<property name="print" column="print"></property>
<property name="abo" column="abo"></property>
<property name="work" column="work"></property>
<property name="card" column="card"></property>
<property name="type" column="type"></property>
<property name="idticket" column="idticket"></property>

</class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
public static void main(String[] args) {
SessionFactory sessionFactory = new Configuration().configure("WEB-INF/hibernate.cfg.xml").buildSessionFactory();

Session session = sessionFactory.openSession();
Transaction transaction = session.beginTransaction();
long startTime = System.currentTimeMillis();
for (int i = 0; i < 100; i++){
List l = session.createQuery("from Ticket where idticket ="+1290870).list();
}
System.out.println("Hibernate: "+((System.currentTimeMillis()-startTime)/1000.0f)+" sek");
transaction.commit();
session.close();

}
Full stack trace of any exception that occurs:

Name and version of the database you are using:
PostgreSQL(version: 8.1.3)
JDBC: postgresql-8.1-408.jdbc3
The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:
2006-12-18 12:18:13 org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.2.1
2006-12-18 12:18:14 org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
2006-12-18 12:18:14 org.hibernate.cfg.Environment buildBytecodeProvider
INFO: Bytecode provider name : cglib
2006-12-18 12:18:14 org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
2006-12-18 12:18:14 org.hibernate.cfg.Configuration configure
INFO: configuring from resource: WEB-INF/hibernate.cfg.xml
2006-12-18 12:18:14 org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: WEB-INF/hibernate.cfg.xml
2006-12-18 12:18:17 org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource : pl/net/kowalski/xmlData/Ticket.hbm.xml
2006-12-18 12:18:18 org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: pl.net.kowalski.bizness.Dane.Ticket -> ticket
2006-12-18 12:18:18 org.hibernate.cfg.Configuration doConfigure
INFO: Configured SessionFactory: null
2006-12-18 12:18:19 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Using Hibernate built-in connection pool (not for production use!)
2006-12-18 12:18:19 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 20
2006-12-18 12:18:19 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: autocommit mode: false
2006-12-18 12:18:19 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: org.postgresql.Driver at URL: jdbc:postgresql://***.***.***.**/bskd
2006-12-18 12:18:19 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=marcin, password=****}
2006-12-18 12:18:19 org.hibernate.cfg.SettingsFactory buildSettings
INFO: RDBMS: PostgreSQL, version: 8.1.3
2006-12-18 12:18:19 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC driver: PostgreSQL Native Driver, version: PostgreSQL 8.1 JDBC3 with SSL (build 408)
2006-12-18 12:18:19 org.hibernate.dialect.Dialect <init>
INFO: Using dialect: org.hibernate.dialect.PostgreSQLDialect
2006-12-18 12:18:19 org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
INFO: Using default transaction strategy (direct JDBC transactions)
2006-12-18 12:18:19 org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
2006-12-18 12:18:19 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic flush during beforeCompletion(): disabled
2006-12-18 12:18:19 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic session close at end of transaction: disabled
2006-12-18 12:18:19 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch size: 15
2006-12-18 12:18:19 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch updates for versioned data: disabled
2006-12-18 12:18:19 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Scrollable result sets: enabled
2006-12-18 12:18:19 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC3 getGeneratedKeys(): disabled
2006-12-18 12:18:19 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Connection release mode: auto
2006-12-18 12:18:19 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default batch fetch size: 1
2006-12-18 12:18:19 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Generate SQL with comments: disabled
2006-12-18 12:18:19 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL updates by primary key: disabled
2006-12-18 12:18:19 org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
2006-12-18 12:18:20 org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
INFO: Using ASTQueryTranslatorFactory
2006-12-18 12:18:20 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
2006-12-18 12:18:20 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JPA-QL strict compliance: disabled
2006-12-18 12:18:20 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Second-level cache: enabled
2006-12-18 12:18:20 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query cache: disabled
2006-12-18 12:18:20 org.hibernate.cfg.SettingsFactory createCacheProvider
INFO: Cache provider: org.hibernate.cache.NoCacheProvider
2006-12-18 12:18:20 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: disabled
2006-12-18 12:18:20 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Structured second-level cache entries: disabled
2006-12-18 12:18:20 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Statistics: disabled
2006-12-18 12:18:20 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Deleted entity synthetic identifier rollback: disabled
2006-12-18 12:18:20 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default entity-mode: pojo
2006-12-18 12:18:20 org.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
2006-12-18 12:18:21 org.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Not binding factory to JNDI, no JNDI name configured
Hibernate: 4.416 sek


Hi, I've got the same problem.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.