-->
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.  [ 4 posts ] 
Author Message
 Post subject: Turning off caching: what am I neglecting to do?
PostPosted: Wed Aug 12, 2009 12:24 pm 
Beginner
Beginner

Joined: Thu May 28, 2009 10:25 am
Posts: 21
Requirement: obtain the latest entity data
Complication: In our application, the database row data can be directly updated via SQL statements(as opposed to being updated by the Hibernate ORM)
Issue:

1. I execute an infinite loop that
i.starts a session via the session factory
ii. query for and retrieves a particular object and dumps its data
iii. closes the session

2. While this loop is executing, I execute a command line SQL statement updating a field value corresponding to the object retrieved in (1).
3. I observe that 1 still continues to dump the old field value. In my Hibernate configuration, I disabled "Second-level cache" and "Query cache" so there must be something else I'm neglecting to do.


Here's the hibernate startup log with all the parameters
Code:
11:09:40,480  INFO TransactionManagerLookupFactory:80 - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
11:09:40,496  INFO SettingsFactory:170 - Automatic flush during beforeCompletion(): enabled
11:09:40,496  INFO SettingsFactory:174 - Automatic session close at end of transaction: disabled
11:09:40,496  INFO SettingsFactory:181 - JDBC batch size: 15
11:09:40,496  INFO SettingsFactory:184 - JDBC batch updates for versioned data: disabled
11:09:40,496  INFO SettingsFactory:189 - Scrollable result sets: enabled
11:09:40,496  INFO SettingsFactory:197 - JDBC3 getGeneratedKeys(): enabled
11:09:40,496  INFO SettingsFactory:205 - Connection release mode: auto
11:09:40,496  INFO SettingsFactory:229 - Maximum outer join fetch depth: 2
11:09:40,496  INFO SettingsFactory:232 - Default batch fetch size: 1
11:09:40,496  INFO SettingsFactory:236 - Generate SQL with comments: disabled
11:09:40,496  INFO SettingsFactory:240 - Order SQL updates by primary key: disabled
11:09:40,496  INFO SettingsFactory:244 - Order SQL inserts for batching: disabled
11:09:40,496  INFO SettingsFactory:420 - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
11:09:40,496  INFO ASTQueryTranslatorFactory:47 - Using ASTQueryTranslatorFactory
11:09:40,496  INFO SettingsFactory:252 - Query language substitutions: {}
11:09:40,496  INFO SettingsFactory:257 - JPA-QL strict compliance: disabled
11:09:40,496  INFO SettingsFactory:262 - Second-level cache: disabled=====================>disabled
11:09:40,496  INFO SettingsFactory:266 - Query cache: disabled===================>disabled
11:09:40,496  INFO SettingsFactory:405 - Cache region factory : org.hibernate.cache.impl.NoCachingRegionFactory
11:09:40,496  INFO SettingsFactory:276 - Optimize cache for minimal puts: disabled
11:09:40,496  INFO SettingsFactory:285 - Structured second-level cache entries: disabled
11:09:40,496  INFO SettingsFactory:314 - Statistics: disabled
11:09:40,496  INFO SettingsFactory:318 - Deleted entity synthetic identifier rollback: disabled
11:09:40,496  INFO SettingsFactory:333 - Default entity-mode: pojo
11:09:40,496  INFO SettingsFactory:337 - Named query checking : enabled
11:09:40,527  INFO SessionFactoryImpl:187 - building session factory
11:09:40,793  INFO SessionFactoryObjectFactory:105 - Not binding factory to JNDI, no JNDI name configured


Code:
   @SuppressWarnings("unchecked")
   public List<Attribute> getAttributes(List<Long> attributeIdList) throws SystemFailureException {
      HibernateSessionHelper sessionHelper = null;
      Session session = null;
      List<Attribute> attrList = null;
      try {
         sessionHelper = HibernateSessionHelperSingletonFactory.GetInstance();
         session = sessionHelper.beginSession(entityClasses);
         attrList = (List<Attribute>)session.createQuery("from Attribute as attr where attr.id in (:IdList)").setParameterList("IdList", attributeIdList).list();
      } catch (HibernateException e) {
         throw new SystemFailureException(e);
      } finally {
         if (session != null)
            sessionHelper.closeSession(session, false);
      }
      return attrList;
   }


Thanks for any suggestions.


Top
 Profile  
 
 Post subject: Re: Turning off caching: what am I neglecting to do?
PostPosted: Wed Aug 12, 2009 4:00 pm 
Beginner
Beginner

Joined: Thu May 28, 2009 10:25 am
Posts: 21
I looked at this further. I can also get the issue to occur by
1. Run a hibernate query for an object in a continuous loop and dump its members to screen
2. While the above program is executing, execute a separate program modifying some member property .
3. After (2), a command line select query in MySQL shows that the property has been modified, .. but the program (1) running in a continuous loop still prints the old value.

I guess the programs in (1) and (2) are running off different session factories, . but this is strange? How do I resolve the issue.

These were the options I used when defining the session factory:

Code:
sessionFactory = new HibernateSessionFactoryBuilder().setProperty("hibernate.cache.use_query_cache", "false").setProperty("hibernate.cache.use_second_level_cache", "false").setProperty("hibernate.connection.username", "root").setProperty("hibernate.connection.password", "*********").setProperty("hibernate.connection.url", "jdbc:mysql://localhost/mydb").addResources(configurationClasses).build();


Top
 Profile  
 
 Post subject: Re: Turning off caching: what am I neglecting to do?
PostPosted: Wed Aug 12, 2009 4:29 pm 
Newbie

Joined: Wed Aug 12, 2009 4:24 pm
Posts: 1
Maybe this thread can help:
viewtopic.php?f=1&t=950048&view=previous

also I found this article on Google with step by step instructions:
http://www.java2s.com/Tutorial/Java/035 ... igFile.htm

_________________
Dallas criminal defense lawyers


Top
 Profile  
 
 Post subject: Re: Turning off caching: what am I neglecting to do?
PostPosted: Wed Aug 12, 2009 6:19 pm 
Beginner
Beginner

Joined: Thu May 28, 2009 10:25 am
Posts: 21
Fixed!!!!

Drilling down further, I've noticed that the autocommit property is responsible for the issue I'm seeing. When the property is false, I see the issue, and when it's true, queries return the updated result.

Code:
...........
      .setProperty("hibernate.connection.autocommit", "true")


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