Hibernate version: 3.2
I have a simple MySql5 Database. I am storing only some Data inside. The problem is that when i update Data or insert new Rows, my Hibernate-Query does not update the data in the same time! It needs some Seconds to notify that there is new/changed Data in the database.
How can i deactivate Caching or Update the Cache faster?
Here my Mapping:
Code:
<hibernate-mapping>
<class name="package.RequestStatistic" >
<id name="id" type="long">
<generator class="native">
</generator>
</id>
<property name="error" type="integer"/>
<property name="cache" type="integer"/>
<property name="request" type="integer"/>
<property name="timestamp" type="java.sql.Timestamp"/>
</class>
</hibernate-mapping>
And here the Query-Function:
Code:
public List queryDay(java.sql.Timestamp from, java.sql.Timestamp to) throws InfrastructureException {
List result;
try {
Session session = HibernateUtil.getSession();
session.flush();
session.clear();
String queryString = "from RequestStatistic rs "
+ "where rs.timestamp >= :from and "
+ "rs.timestamp <= :to";
Query q = session.createQuery(queryString)
.setParameter("from", from, Hibernate.TIMESTAMP)
.setParameter("to", to, Hibernate.TIMESTAMP);
result = q.list();
}
catch (HibernateException ex) {
System.out.println("Error:" + ex.toString());
}
return result;
}
And here the "HibernateUtil.getSession()"-Function:
Code:
...
private static final ThreadLocal threadSession = new ThreadLocal();
...
public static Session getSession() throws InfrastructureException {
Session s = (Session) threadSession.get();
try {
if (s == null) {
log.debug("Opening new Session for this thread.");
if (getInterceptor() != null) {
log.debug("Using interceptor: " + getInterceptor().getClass());
s = getSessionFactory().openSession(getInterceptor());
}
else {
s = getSessionFactory().openSession();
}
threadSession.set(s);
}
}
catch (HibernateException ex) {
throw new InfrastructureException(ex);
}
return s;
}