-->
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.  [ 4 posts ] 
Author Message
 Post subject: Slow start at login
PostPosted: Thu Aug 17, 2006 1:27 pm 
Newbie

Joined: Mon May 08, 2006 10:00 am
Posts: 8
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.0

Once the user logs-in in to the application, then only it takes long time to load the page with data from database. Iam using an hibernate to populate the data from single table only. Other calls to database using hibernate after first call is faster. What can be done to load the hibernate configuration to perform better after login ?

Hibernate cnf. xml ->

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"
>

<hibernate-configuration>
<session-factory name="java:comp/env/hibernate/SessionFactory">

<property name="connection.url">dbURL</property>
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="connection.username">userA</property>
<property name="connection.password"></property>
<property name="connection.autocommit">false</property>
<property name="connection.shutdown">true</property>
<property name="dialect">org.hibernate.dialect.OracleDialect</property>
<property name="cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property>
<property name="hibernate.cglib.use_reflection_optimizer">false</property>
<mapping resource="ClassA.hbm.xml"/>
</session-factory>
</hibernate-configuration>

Here is my ClassA.hbm.xml mapping file ->

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping auto-import="true" package="packageA">
<class name="ClassA" table="tableA" lazy="false">
<generator class="native">
<param name="sequence">SEQA</param> </generator>
</id>
<property name="field1" column="field1"/>
<property name="field2" column="field2"/>
</class>
</hibernate-mapping>

Thanks.
Amit.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 17, 2006 3:01 pm 
Expert
Expert

Joined: Tue Dec 07, 2004 6:57 am
Posts: 285
Location: Nürnberg, Germany
Hi,
are you ramping up your SessionFactory for every User Session?

If yes, it's wrong. The SessionFactory can be used by every Session.

Bye,
Mike

_________________
Please don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 18, 2006 9:04 am 
Newbie

Joined: Mon May 08, 2006 10:00 am
Posts: 8
Mike,

Thanks for reply.

Here's my code -

In Implimentation calss >>

session = Utils.getSession();
trans = session.beginTransaction();
// <coding>
session.save(aClassA);
trans.commit();
aUtils.releaseSession(session);

and in Utils.java >>
static {
try {
Configuration configuration = new Configuration();
configuration.setProperty(Environment.SHOW_SQL, "false"); configuration.addClass(ClassA.class);
sessionFactory = configuration.buildSessionFactory();
}
catch (Exception e) {
<exception msg>
}

public static Session getSession() {
return sessionFactory.openSession();
}

public static void releaseSession(Session session) {
session.close();
}


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 18, 2006 4:03 pm 
Beginner
Beginner

Joined: Wed Jun 21, 2006 10:08 am
Posts: 26
initialize Hibernate at the webapp startup.

Code:
public class HibernateListener implements ServletContextListener {

    private static Log log = LogFactory.getLog(HibernateListener.class);

    public void contextInitialized(ServletContextEvent event) {
        log.info("Starting Hibernate persistence service...");
        long start = Calendar.getInstance().getTimeInMillis();
        HibernateUtil.getSessionFactory(); // Just call static initializer
        long end = Calendar.getInstance().getTimeInMillis();
        log.info("Hibernate startup completed in: " + (end-start) + "millis");
    }

    public void contextDestroyed(ServletContextEvent event) {
        log.info("Shutting down Hibernate persistence service...");
        long start = Calendar.getInstance().getTimeInMillis();
        HibernateUtil.shutdown();
        long end = Calendar.getInstance().getTimeInMillis();
        log.info("Hibernate shutdown completed in: " + (end-start) + "millis");
    }


And in your web xml, put:
<listener>
<listener-class>x.y.z.HibernateListener</listener-class>
</listener>

_________________
- Jonathan


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