-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 11 posts ] 
Author Message
 Post subject: getCurrentSession behaving different on Windows, Linux
PostPosted: Sun Apr 22, 2007 6:25 am 
Newbie

Joined: Fri Mar 30, 2007 5:28 pm
Posts: 8
My HibernateUtils class is
static {
sessionFactory = new Configuration().configure("conf/hibernate.cfg.xml").buildSessionFactory();

}
public static void returnCurrentSession(){
getCurrentSession().getTransaction().commit();

}

public static Session getCurrentSession(){
Session sess = sessionFactory.getCurrentSession();
sess.beginTransaction();
return sess;
}


I am using tomcat.
This works fine in Windows. On Linux; first time after server started, it works fine; but next time it starts giving me following erros when i try to execute any query getting session using HibernateUtils.getCurrentSession(). I noticed that on Linux default mySQL engine is MyISAM so I changed the dialect accordingly but it didnt help.



Apr 21, 2007 6:56:05 PM org.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 0, SQLState: 08003
Apr 21, 2007 6:56:05 PM org.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: No operations allowed after connection closed.Connection was implicitly closed due to underlying exception/error:


** BEGIN NESTED EXCEPTION **

com.mysql.jdbc.CommunicationsException
MESSAGE: Communications link failure due to underlying exception:

** BEGIN NESTED EXCEPTION **

java.io.EOFException

STACKTRACE:

java.io.EOFException
at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:1963)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2375)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2874)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1623)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1715)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3249)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1268)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1403)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1778)
at org.hibernate.loader.Loader.doQuery(Loader.java:662)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2211)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2095)
at org.hibernate.loader.Loader.list(Loader.java:2090)


org.apache.jasper.JasperException: org.hibernate.exception.JDBCConnectionException: could not execute query
at org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:532)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:426)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)



Help is highly appreciated. I am stuck in this for so long :(
Display posts from previous:


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 22, 2007 6:34 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
java.io.EOFException
at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:1963)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2375)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2874)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1623)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1715)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3249)

Obviously your JDBC driver/MySQL stuff is broken. Try without Hibernate and you will get the same exception.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject: getCurrentSession behaving different on Windows, Linux
PostPosted: Sun Apr 22, 2007 7:00 am 
Newbie

Joined: Fri Mar 30, 2007 5:28 pm
Posts: 8
When I run the code and queries for the first item it goes through. It gives me error only when i run it the second time


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 22, 2007 7:04 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
So don't use this messy HibernateUtil stuff you patched together but the one from here: http://hibernate.org/42.html

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 22, 2007 7:06 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
And if you want people to understand what you are actually doing you need to post much more code.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 22, 2007 12:10 pm 
Newbie

Joined: Fri Mar 30, 2007 5:28 pm
Posts: 8
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.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 22, 2007 12:21 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
NidhiAgarwal wrote:

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.


No, this is not what you are doing. There is no "HibernateUtils.getCurrentSession()" and any "returnCurrentSession()" stuff mentioned anywhere in any tutorial. Follow the tutorials to the _letter_.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 22, 2007 1:32 pm 
Newbie

Joined: Fri Mar 30, 2007 5:28 pm
Posts: 8
I tried even this
Session sess = HibernateUtils.getSessionFactory().getCurrentSession();
sess.beginTransaction();
java.util.List li = sess.createCriteria(com.lottos.domain.User.class).list();
out.println (li.size());
sess.getTransaction().commit();


Still same problem. Once I change the query; exception happened.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 22, 2007 1:38 pm 
Newbie

Joined: Fri Mar 30, 2007 5:28 pm
Posts: 8
do u feel that hibernate.cfg.xml is fine ? is there anything specific to Operating system because its working ifne on windows.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 22, 2007 2:50 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Well, I already said that you have a driver/database issue that has nothing to do with Hibernate, but you didn't want to hear that. [/url]

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 23, 2007 1:09 am 
Newbie

Joined: Fri Mar 30, 2007 5:28 pm
Posts: 8
well i am not convinced that its a DB issue else it wont work first time.. Its not just first time but first time after ever tomcat restart..

Also, if I use openSession() it works perfectly. If DB would have been an issue; openSession() wont have worked.

I have decided to use ThreadLocal and implement getCurrentSession() on my own rather than believe that provided by hibernate.

Thanks a lot for your time Christina.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 11 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.