-->
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: Problems with cache refresh
PostPosted: Mon Dec 11, 2006 5:42 am 
Newbie

Joined: Mon Dec 11, 2006 5:18 am
Posts: 9
Hello,
I'm using Hibernate 3.1.3 with Tomcat 5.5.20, SqlServer2000 and Java 5(updater 09) . I have a problem in refreshing my data.

I select a data row and change some data. I store the data to the database
and the data is persistent.

If I do a new select the new data is visible, but if I do a select for more times the data is alternately visible or not. The old values stored before are shown.

Furthermore if I do the select from a second browser the stored data from this browser are not visible in the other browser.

My hibernate.cfg:


<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration
PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<property name="hbm2ddl.auto">true</property>
<property name="hibernate.cache.use_query_cache">false</property>
<property name="hibernate.cache.use_second_level_cache">false</property>
<property name="hibernate.connection.aggressive_release">false</property>
</session-factory>
</hibernate-configuration>



I'm using transaction.
I'm using an helper class to manage Session.
I'm using an external connection pool. Follow class



public static Session getSession(Connection conn)
{
Session session = (Session) HibernateHelper.session.get();
if (session == null)
{
session = sessionFactory.openSession(conn);
HibernateHelper.session.set(session);
}
else
{
if(!session.isConnected())
session.reconnect(conn);
else
System.out.println("HibernateHelper");
}
return session;
}

public static Session createSession(Connection conn)
{
return sessionFactory.openSession(conn);
}

private static final ThreadLocal session = new ThreadLocal();
private static final ThreadLocal transaction = new ThreadLocal();
private static final SessionFactory sessionFactory = getConfigurator().buildSessionFactory();

private static Configuration getConfigurator()
{
String basePath=System.getProperty("BasePath");


final String filePath = basePath+"hibernate.cfg.xml";

Configuration configure = new Configuration().configure(new File(filePath));

configure.addDirectory(new File(basePath+"HBM/zucchetti/business/datatype/structure/"));
configure.addDirectory(new File(basePath+"HBM/zucchetti/iseBase/business/datatype/structure/"));


return configure;
}


I tryed to use evict after call update / get / save
I tryed to use clear

The strange thing is that if I use WebSphere5.1 all runs OK. Only with tomcat doesn't run (that obviously is the App Serv used in production ...)

any idea ????

Thank yopu in advance
Ale.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 11, 2006 5:48 am 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
I can't see the code you're using to save your data. Do you begin and commit a transaction for this ? If the data is commited, you should be able to see it from anywhere without problem.

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 11, 2006 6:11 am 
Newbie

Joined: Mon Dec 11, 2006 5:18 am
Posts: 9
Hi, batmat

here's the code of the CRUD:


Code:
public class AddettiAttestazioneDSUCRUD
{

    public AddettiAttestazioneDSUCRUD()
    {
       
    }
   
    public AddettoAttestazioneDSU_t create(AddettoAttestazioneDSU_t addetto, HibernateDatabase conn)
    {
        conn.getHibernateSession().save(addetto);
        return addetto;
    }
   
    public AddettoAttestazioneDSU_t get(int IDAddetto, HibernateDatabase conn)
    {
        AddettoAttestazioneDSU_t addetto = (AddettoAttestazioneDSU_t) conn.getHibernateSession().get(AddettoAttestazioneDSU_t.class, new Integer(IDAddetto));
        return addetto;
    }
   
    public void update(AddettoAttestazioneDSU_t addetto, HibernateDatabase conn)
    {
        conn.getHibernateSession().update(addetto);
    }
   
    public void delete(int IDAddetto, HibernateDatabase conn)
    {
        AddettoAttestazioneDSU_t c = (AddettoAttestazioneDSU_t) conn.getHibernateSession().load(AddettoAttestazioneDSU_t.class,new Integer(IDAddetto));
        if(c == null)
        {
            c = new AddettoAttestazioneDSU_t();
            c.setIDAddetto(IDAddetto);
        }
        conn.getHibernateSession().delete(c);
    }
}


here's the code of the list of the above elements
Code:

public class AddettiAttestazioneDSUMgr implements IAddettiAttestazioneDSUMgt
{

    public AddettiAttestazioneDSUMgr()
    {
        super();
    }

    public AddettoAttestazioneDSU_t[] getElencoAddettiAttestazioneDSU(String visibilita, String cognome, String nome, String ufficio, String codiceCaf, String codiceSede, OrdinamentiRicerche.OrdinamentoAddettiDSU_e ordinamento, TipoOrdinamentoRicerca_e dir, int maxRows, HibernateDatabase conn) throws ZMaxRowLimitException, ZSystemException
    {
        Session session = conn.getHibernateSession();

       
        Criteria crit = session.createCriteria(AddettoAttestazioneDSU_t.class);
       
        crit.add(Restrictions.ilike("cognome",cognome,MatchMode.START));
        crit.add(Restrictions.ilike("nome",nome,MatchMode.START));
        crit.add(Restrictions.ilike("ufficio",ufficio,MatchMode.START));
        Criteria joinCaf = crit.createCriteria("caf","joinCaf",Criteria.LEFT_JOIN);
        if(!NullValue.STRING.equalsIgnoreCase(codiceCaf))
        {
            joinCaf.add(Restrictions.ilike("codice",codiceCaf,MatchMode.START));
        }
        Criteria joinSede = crit.createCriteria("sede","joinSede",Criteria.LEFT_JOIN);
        if(!NullValue.STRING.equalsIgnoreCase(codiceSede))
        {
            joinSede.add(Restrictions.ilike("codice",codiceSede,MatchMode.START));   
        }
        if(!NullValue.STRING.equalsIgnoreCase(visibilita))
        {
            crit.add(Restrictions.sqlRestriction(visibilita)); 
        }
       
        ArrayList lista = new ArrayList();
        lista.add(OrderByUtility.getOrder(dir,"cognome"));
        lista.add(OrderByUtility.getOrder(dir,"nome"));
        lista.add(OrderByUtility.getOrder(dir,"ufficio"));
        lista.add(OrderByUtility.getOrder(dir,joinCaf.getAlias()+".codice"));
        lista.add(OrderByUtility.getOrder(dir,joinSede.getAlias()+".codice"));
       
        lista.add(0,lista.remove(ordinamento.getOrdinal()));
     
        for (int i = 0; i < lista.size(); i++)
        {
            crit.addOrder((Order) lista.get(i));
        }

        crit.setMaxResults(++maxRows);
       
        List l = crit.list();
        if(l.size() > maxRows)
        {
            //Se il numero di elementi รจ maggiore
            //tolgo l'utlimo e lancio l'exception
            l.remove(maxRows);
            throw new ZMaxRowLimitException(l.toArray(new AddettoAttestazioneDSU_t[l.size()]));
        }
      return (AddettoAttestazioneDSU_t[]) l.toArray(new AddettoAttestazioneDSU_t[l.size()]);
    }
   
    public AddettoAttestazioneDSU_t createAddettoAttestazioneDSU(AddettoAttestazioneDSU_t addetto, HibernateDatabase conn) throws ZSystemException
    {
        return new AddettiAttestazioneDSUCRUD().create(addetto,conn);
    }

    public AddettoAttestazioneDSU_t getAddettoAttestazioneDSU(int IDAddetto, HibernateDatabase conn) throws ZSystemException
    {
        return new AddettiAttestazioneDSUCRUD().get(IDAddetto,conn);
    }

    public void updateAddettoAttestazioneDSU(AddettoAttestazioneDSU_t addetto, HibernateDatabase conn) throws ZSystemException
    {
        new AddettiAttestazioneDSUCRUD().update(addetto,conn);
    }

    public void deleteAddettoAttestazioneDSU(int IDAddetto, HibernateDatabase conn) throws ZSystemException
    {
        new AddettiAttestazioneDSUCRUD().delete(IDAddetto,conn);
    }

    public AddettoAttestazioneDSU_t createEmptyAddettoAttestazioneDSU() throws ZSystemException
    {
        return new AddettoAttestazioneDSU_t();
    }

}




- HibernateDatabase is our wrapper of hibernate.

- The data is realy written on the database, I see it using Sql Server Enterprise Manager


The operation of begin - transaction and commit / rollback are executed. They are managed from a base class of MVC2.


I hope this is usefull.
Ale


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 12, 2006 4:17 am 
Newbie

Joined: Mon Dec 11, 2006 5:18 am
Posts: 9
RESOLVED !!!

The problem was in the HibernetHelper class that in Tomcat doesn't run correctly.


Using the classic:


Code:
public static Session getSession(Connection conn) {
      
         return sessionFactory.openSession(conn);
}
   
private static final SessionFactory sessionFactory = ...



and

Code:
- <!--  Disable all cache eccept  first level
  -->
  <property name="hibernate.cache.use_query_cache">false</property>
  <property name="hibernate.cache.use_second_level_cache">false</property>
  <property name="hibernate.connection.aggressive_release">false</property>
  <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
- <!--
  thread is the short name for
            org.hibernate.context.ThreadLocalSessionContext
            and let Hibernate bind the session automatically to the thread

  -->
  <property name="current_session_context_class">thread</property>



all is OK.

Hope this is usefull.
Ale


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 13, 2006 12:59 pm 
Newbie

Joined: Mon Dec 11, 2006 5:18 am
Posts: 9
alexsil wrote:
RESOLVED !!!

The problem was in the HibernetHelper class that in Tomcat doesn't run correctly.


Using the classic:


Code:
public static Session getSession(Connection conn) {
      
         return sessionFactory.openSession(conn);
}
   
private static final SessionFactory sessionFactory = ...



and

Code:
- <!--  Disable all cache eccept  first level
  -->
  <property name="hibernate.cache.use_query_cache">false</property>
  <property name="hibernate.cache.use_second_level_cache">false</property>
  <property name="hibernate.connection.aggressive_release">false</property>
  <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
- <!--
  thread is the short name for
            org.hibernate.context.ThreadLocalSessionContext
            and let Hibernate bind the session automatically to the thread

  -->
  <property name="current_session_context_class">thread</property>



all is OK.

Hope this is usefull.
Ale


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.