Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 3.x
Mapping documents: 3
Code between sessionFactory.openSession() and session.close():
Code:
// uncommenting this line gets new records
//this.articleSessionFactory = this.buildSessionFactory();
Session session = this.articleSessionFactory.openSession();
try {
DateFormat dateFormat = DateFormat.getDateTimeInstance(
DateFormat.SHORT, DateFormat.LONG);
Date timeStamp = dateFormat.parse(this.getConfiguration()
.getString(IssueSynchronization.SYNCH_TIMESTAMP));
Query namedQuery = session.getNamedQuery(this.getConfiguration()
.getString(IssueSynchronization.HIBERNATE_QUERY));
namedQuery.setTimestamp("created", timeStamp);
List list = namedQuery.list();
String formattedTimeStamp = dateFormat.format(timeStamp);
// code to update timestamp elided
IssueSynchronization.LOG.info(MessageFormat
.format("Read {0} articles published since {1}",
new Object[] { Integer.toString(list.size()), formattedTimeStamp }));
} catch (Throwable t) {
throw new SynchronizationException(t);
} finally {
session.close();
}
Undoubtedly this is something a noob like me is not "getting" - but after looking at docs, posts, etc. I still cannot figure this out: The query results only include new records (inserts from a separate web app) if when a new SessionFactory is created. Without that ugliness an empty list is returned (no new inserts found). This should clue me into what is going on...but unfortunately I'm at a loss right now.
Any insight is appreciated. Btw, I have not deviated for default configuration (of hibernate properties, ehcache, etc.) - in fact I have not even deployed an ehcache.xml.