Hibernate version: 3.2.4
Mapping documents:
Code:
<class name="Documents" table="DOCUMENTS_TABLE" >
<id name="docId" column="DOC_ID"/>
<property name="refNo" column="REF_NO"/>
<property name="document" column="DOCUMENT_BLOB" type="blob"/>
</class>
Code between sessionFactory.openSession() and session.close():Code:
Query query = session.createQuery("from Documents where refNo = '222'");
List appRefNoList = query.list();
Full stack trace of any exception that occurs:none
Name and version of the database you are using: Oracle 9i
The generated SQL (show_sql=true): none
Debug level Hibernate log excerpt: none
Can anyone help me in using a hibernate session from a class that extends java.lang.Thread. My class is a daemon thread that runs continuously. It makes use of hibernate session at regular intervals.
I had used the following code to get Hibernate Session,
but it didn't work in the thread. It works fine when I run it from a
non-thread java class.
Code:
public class HibernateSession {
public static final ThreadLocal session = new ThreadLocal();
public static Session currentSession() throws HibernateException {
Session s = (Session) session.get();
if (s == null) {
SessionFactory sf = HibernateUtil.getSessionFactory();
s = sf.openSession();
session.set(s);
}
return s;
}
public static void closeSession() throws HibernateException {
Session s = (Session) session.get();
session.set(null);
if (s != null) s.close();
}
}
Thanks in advance.
Regards,
Krishna Mohan.