When I use external MySQL Client it works fine. When I restart my tomcat (which initializes HibernateSessionFactory) it works fine for first time.
Following are the strategies discussed on
http://hibernate.org/42.html
1. Transaction demarcation with JTA: I want to keep things simple. So using plain JDBC and no JTA until and unless its possible to get my work done using JDBC.
2. Transaction demarcation with plain JDBC: This is what exactly I am doing. I execute code in following way:
Session sess = HibernateUtils.getCurrentSession();
sess.save(user);// do some work
HibernateUtils.returnCurrentSession();
I got this strategy of creating a HibernateUtils from first tutorial I read on hibernate.org.
3. Transaction demarcation with EJB/CMT: I want to keep things simple. anyway i dont have ejb container.
4. What about the SessionFactory? This is exactly what i am doing of creating HibernateUtil.
Regarding the code I am using :
hibernate.cfg.xml :
<property name="hibernate.connection.pool_size">5</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLMyISAMDialect</property>
<property name="hibernate.transaction.factory_class"> org.hibernate.transaction.JDBCTransactionFactory</property>
<property name="hibernate.current_session_context_class">thread</property>
<property name="hibernate.cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
HibernateUtils: Already mentioned above in first message.
Test Bean code:
Session sess = HibernateUtils.getCurrentSession();
java.util.List list = sess.createCriteria(User.class).list();
HibernateUtils.returnCurrentSession(sess);
After the server restart if I keep executing above query only it will work ok (probably it gets it from cache so dont have to go to DB);
but moment I change the SQL Query; it throws the exception. Restarting the server with new query again works fine
Thanks for taking time to answer my query.