-->
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: Cache updates to slow?
PostPosted: Fri Nov 17, 2006 5:27 am 
Regular
Regular

Joined: Mon Jul 31, 2006 4:59 pm
Posts: 53
Hibernate version: 3.2


I have a simple MySql5 Database. I am storing only some Data inside. The problem is that when i update Data or insert new Rows, my Hibernate-Query does not update the data in the same time! It needs some Seconds to notify that there is new/changed Data in the database.

How can i deactivate Caching or Update the Cache faster?

Here my Mapping:
Code:
<hibernate-mapping>

   <class name="package.RequestStatistic" >
   
   
      <id name="id" type="long">
         <generator class="native">
         </generator>
      </id>
      
      <property name="error" type="integer"/>
      <property name="cache" type="integer"/>
      <property name="request" type="integer"/>
      <property name="timestamp" type="java.sql.Timestamp"/>
         
   </class>
</hibernate-mapping>



And here the Query-Function:
Code:
public List queryDay(java.sql.Timestamp from, java.sql.Timestamp to) throws InfrastructureException {
   
        List result;
       
        try {
          
           Session session = HibernateUtil.getSession();
           session.flush();
           session.clear();
          
          
         
             
           String queryString = "from RequestStatistic rs " 
                                + "where rs.timestamp >= :from and "
                             + "rs.timestamp <= :to";
           Query q = session.createQuery(queryString)
              .setParameter("from", from, Hibernate.TIMESTAMP)
              .setParameter("to", to, Hibernate.TIMESTAMP);
          
           result = q.list();
                  
       
        }
        catch (HibernateException ex) {
            System.out.println("Error:" + ex.toString());
      
          }
       
        return result;
    }



And here the "HibernateUtil.getSession()"-Function:
Code:
...
private static final ThreadLocal threadSession = new ThreadLocal();
...

public static Session getSession() throws InfrastructureException {

   Session s = (Session) threadSession.get();
   
   
    try {
      if (s == null) {
        log.debug("Opening new Session for this thread.");
        if (getInterceptor() != null) {
          log.debug("Using interceptor: " + getInterceptor().getClass());
          s = getSessionFactory().openSession(getInterceptor());
        }
        else {
          s = getSessionFactory().openSession();
        }
        threadSession.set(s);
      }
    }
    catch (HibernateException ex) {
      throw new InfrastructureException(ex);
    }
   

   
    return s;
   
  }


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 17, 2006 5:47 am 
Regular
Regular

Joined: Mon Jul 31, 2006 4:59 pm
Posts: 53
So i noticed that the cache is much faster, when i use this commands:

Code:
public List queryDay(java.sql.Timestamp from, java.sql.Timestamp to) throws InfrastructureException {
   
        List result;
       
        try {
          
           Session session = HibernateUtil.getSession();
           session.flush();
           session.clear();
           HibernateUtil.commitTransaction();

....


Is this ok that i use the "commitTransaction"-command on this position?


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.