-->
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.  [ 1 post ] 
Author Message
 Post subject: speed looking up database
PostPosted: Wed Sep 02, 2009 3:46 pm 
Newbie

Joined: Wed Jun 24, 2009 11:34 am
Posts: 13
We are experiencing some slow connections with hibernate. Right whenever we call a service, it seems to pause about 5 seconds before making the connection and searching. Here is the code we are making on the first call:
Code:
public AbstractUser login(String username, String password){
      //Configuration cfg = new Configuration().addResource("hibernate.cfg.xml");
      //SessionFactory sessionFactory= cfg.buildSessionFactory();
      
      SessionFactory sessionFactory;
      sessionFactory = new AnnotationConfiguration()
        .addAnnotatedClass(AbstractUser.class)
        .addAnnotatedClass(CourseSession.class)
        .addAnnotatedClass(Course.class)
        .addAnnotatedClass(Message.class)
        .addAnnotatedClass(Material.class)
        .addAnnotatedClass(MaterialSession.class)
        .addAnnotatedClass(Step.class)
        .addAnnotatedClass(Section.class)
        .addAnnotatedClass(Topic.class)
        .addAnnotatedClass(Subtopic.class)
        .setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLInnoDBDialect")
        .buildSessionFactory();
      sessionFactory.openSession();
      EntityManagerFactory emf = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT);                             
      EntityManager em = emf.createEntityManager();                         
      Query q = em.createNamedQuery("users.byUnPass");                         
      q.setParameter("username", username);   
      q.setParameter("password", password);
      AbstractUser user;
      
      try{
         user = (AbstractUser) q.getSingleResult();
      }catch(javax.persistence.NoResultException e){
         user = new AbstractUser();
      }
      
      return user;
   }

We are using annotations, I am not sure if that is a slower method of lookup than hbm. Also I am not sure of the best way of initialization of annotations to our db. Any advice would be helpful. Also the commented code is for an hbm file that used to serve as our connection, but it didn't like adding the annotations for manytoone and onetomany, so I used the addAnnotatedClass tag to get those relationships read in.
TIA!


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

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.