-->
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.  [ 5 posts ] 
Author Message
 Post subject: Newly inserted data not fetched
PostPosted: Thu Sep 25, 2008 8:43 am 
Newbie

Joined: Thu Sep 25, 2008 8:32 am
Posts: 2
Hello all,

I have been banging my head for 2 days with this problem, i have read the docs and googled everywhere without a clue.

My scenario is the following:

Im working with Sun's JSF and Icefaces. When i insert some data for example i add a new comment to a story then the comment is saved to the database just fine. However when i try to retrieve all comments from another bean i get the old list of comments without the newly inserted comment.

Im using DAO's reverse engineered by MyEclipse. Data is added with transactions so its not cached and it definately writes the data to the database, but retrieving the new data fails. Occasionally when i surf around the page, i might see the new comment displayed but when i surf more its back to the old list again. My beans are request scoped.

I'm most grateful for any tips,advice and help.

Regards,

Jack


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 25, 2008 1:28 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
Most likely, you are using/creating more than one session at a time in your application, instead of using some "managed environment" for session pooling.
How does the code that creates your sessions look?

_________________
Gonzalo Díaz


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 25, 2008 2:25 pm 
Newbie

Joined: Thu Sep 25, 2008 8:32 am
Posts: 2
Yes that is the case..

This is from the autogenerated HibernateSessionFactory.java:

Code:
static {
       try {
         configuration.configure(configFile);
         sessionFactory = configuration.buildSessionFactory();
      } catch (Exception e) {
         System.err
               .println("%%%% Error Creating SessionFactory%%%%");
         e.printStackTrace();
      }
    }

public static Session getSession() throws HibernateException {
        Session session = (Session) threadLocal.get();

      if (session == null || !session.isOpen()) {
         if (sessionFactory == null) {
            rebuildSessionFactory();
         }
         session = (sessionFactory != null) ? sessionFactory.openSession()
               : null;
         threadLocal.set(session);
      }

        return session;
    }

   /**
     *  Rebuild hibernate session factory
     *
     */
   public static void rebuildSessionFactory() {
      try {
         configuration.configure(configFile);
         sessionFactory = configuration.buildSessionFactory();
      } catch (Exception e) {
         System.err
               .println("%%%% Error Creating SessionFactory %%%%");
         e.printStackTrace();
      }
   }


Should i consider a totally new configuration of Hibernate with session pooling?

Thanks,

J


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 25, 2008 6:12 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
That code uses the old ThreadLocal strategy and it doesn't look totally wrong, but most likely there are other parts of your application that manage to call it in such a way, that more than one SessionFactory is created on the fly, wreaking havoc on your application persistency.

It happens all the time.

For any non trivial Hibernate application (and certainly for any Hibernate web application), I recommend that you use some sort of "managed environment" that covers most of the session/transaction wiring problems for you.

I recommend Spring.

If you are interested, in the link below I show how to build a bare-bones Spring+Hibernate web application.

http://hibernar.org/articulos_en/spring ... xample.php

_________________
Gonzalo Díaz


Top
 Profile  
 
 Post subject: Re: Newly inserted data not fetched
PostPosted: Mon Mar 28, 2011 6:36 am 
Newbie

Joined: Tue Dec 28, 2010 2:13 pm
Posts: 2
Hello,

I am a similar problem.

I have a web application and some event on web page inserts into a highly transactional table something like logger.

After inserting immediately I show the log by using getById() method and I don't get the required value from the database (I tried Get ,load n criterion's also)

Later after couple of seconds when I refresh the page I get the value properly. (When executed second time, error is not seen)

Even worse when I debug my program there is no error, whereas when I execute many transactions one after the other in run mode, I get this error which is periodic in nature.

Flush Mode is set to Auto.

I use session Factory to create session.

There are no update done in database outside the application.

Please help me trace the problem

Regards,

Amol
http://cursivetech.com


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