-->
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.  [ 3 posts ] 
Author Message
 Post subject: Hibernate Cache
PostPosted: Mon Nov 07, 2016 10:36 am 
Newbie

Joined: Mon Nov 07, 2016 7:47 am
Posts: 2
Hi. I have a problem with cache of hibernate 4.0.1.Final.
I tried use session clear and evict but not working.
I want not to use cache.
I don't know how but when I don't use session close then the cache is clear.
Today I am doing this for do not use the cache.
This is my method:

Code:
   public List<MyClass> getByFilter(MyClass user){
      session = HibernateConnectionGoogleCloud.getInstanceGoogleCloud();
      List<MyClass> mList = new ArrayList<MyClass>();
      mList = null;
      
      try{
         List<MyClass> list = new ArrayList<MyClass>();

         Criteria criteria = session.createCriteria(MyClass.class);
         
         if(!user.getIdentificador().equals("")){
            criteria.add(Restrictions.eq("identificador", user.getIdentificador()));
         }
                  
         criteria.add(Restrictions.between("data", user.getBeginDate(), user.getEndDate()));
         list = criteria.list();
         
         if(list != null && list.size() > 0)
            mList = list;
         
      }catch (Exception e) {
         e.printStackTrace();
      }finally {
         //session.close();   
      }
      return mList;
   }


session close is commented = no cahce
session close is not commented = with cache


Top
 Profile  
 
 Post subject: Re: Hibernate Cache
PostPosted: Mon Nov 07, 2016 10:43 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
You have multiple options:

1. Either you use a StatelessSession
2. Or you use a read-only Session:

Code:
session.setReadOnly(true);


This way, nothing is going to store in the first-level cache.

As for the second-level cache, unless you explicitly configured it, it will not be activated.


Top
 Profile  
 
 Post subject: Re: Hibernate Cache
PostPosted: Fri Nov 11, 2016 10:02 am 
Newbie

Joined: Mon Nov 07, 2016 7:47 am
Posts: 2
Thank you. The problem is solved.


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