• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regarding slow performance in Hibernate

 
Håkan Axheim
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am building a test program in Java/Hibernate at my work.
I have big problems with performance and connecting to my DB2 database through hibernate.
This is my source code where I make my connection to the DB2 database.

import java.util.logging.Level;
import java.util.logging.Logger;

import org.hibernate.HibernateException;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class HibernateUtilProm803
{
private static final Logger logger = Logger.getLogger(HibernateUtilProm.class.getName());

private static SessionFactory sessionFactory = null;
private static SessionFactory dbFactory = null;

static {
try {
promFactory = new Configuration().configure("resources/db.cfg.xml").buildSessionFactory();

Configuration configuration = new Configuration();
configuration = configuration.configure("resources/db.cfg.xml");
sessionFactory = configuration.buildSessionFactory();
}
catch (HibernateException ex) {
logger.log(Level.SEVERE,"Severe error in initial SesseionFactory " + ex.getMessage());
try {
throw new Exception(ex.getMessage());
}
catch (Exception exception) {
logger.log(Level.SEVERE,ex.getMessage());
}
}
}

public static SessionFactory getSessionFactory() {
return sessionFactory;
}

public static SessionFactory getProm803Factory() {
return promFactory;
}
  
}

This is my db.cfg.xml file
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>

<session-factory>
        <!-- Database connection settings -->
        <property name="hibernate.dialect">org.hibernate.dialect.DB2Dialect</property>
<property name="hibernate.connection.driver_class">com.ibm.db2.jcc.DB2Driver</property>
        <property name="hibernate.connection.url">jdbc:db2://<dbserver>:60000/prom803</property>
        <property name="hibernate.connection.username">username</property>
        <property name="hibernate.connection.password">password</property>
       
        <!-- SQL dialect -->

        <!-- Echo all executed SQL to stdout -->
        <property name="show_sql">true</property>
       
        <property name="current_session_context_class">thread</property>
       
<!-- Mapping files -->
<mapping resource="resources/prom/table_a.hbm.xml"></mapping>
        <mapping resource="resources/prom/table_b.hbm.xml"></mapping>

</session-factory>

</hibernate-configuration> 

what is wrong with this source code and how to code with best performance in hibernate?

 
Dave Tolls
Ranch Hand
Posts: 2095
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What performance issues are you having?
How have you determined there is an issue?
What criteria are you using to determine poor performance?
 
Håkan Axheim
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The program stops at this line --> promFactory = new Configuration().configure("resources/db.cfg.xml").buildSessionFactory();  when I debug the application.
I get no exception. Nothing is written in my log file.
 
Dave Tolls
Ranch Hand
Posts: 2095
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there anything in the logs to show where exactly in buildSessionFactory it is getting stuck?
 
Paul Clapham
Sheriff
Posts: 21565
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you had posted properly indented code then this strange piece of code would have been more apparent;



If you want to log the message from an exception then you don't need all of that tricky stuff where you throw an exception only to immediately catch it. This instead:



Also, I haven't ever used java.util.logging classes but don't they have something which can log an Exception rather than a String? That would have the advantage that you would get the stack trace of the Exception and not just its text.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic