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.