Hibernate version: 3,0
Name and version of the database you are using: mysql 4.1
Hallo ich verwende Hibernate zusammen mit Tomcat und POJOs
Dabei kann ich ohne Probleme mit Hibernate auf meine Datenbank zugreifen. Der Tomcat selbst läuft einer Red Hat Maschine.
Problematisch wird es erst, wenn ich meinen Tomcat über Nacht laufen lasse und am nächsten Morgen meine Anwendung erneut auf die Datenbank zugreifen will.
Die Anwendung versucht noch mit
session.createQuery(blabla)
auf die DB zuzugreifen und dann kracht es.
Bin jetzt auf der Suche, warum es hier kracht! Würde mich freuen, wenn mir einer einen Tip geben kann, in welche Richtung ich suchen sollte.
Unten habe ich den verwendeten Code und den Stacktrace angehängt.
Meine Ideen gehen in die Richtung
- ThreadLocal ??
- cfg.buildSessionFactory
- und wie kann ich diesen Fehler schon in meiner Sessionfactory erkennen?
Leider kann ich den Fehler nur einmal am Tag ausprobieren ;-(( und würde mich deshalb über hinweise freuen
Danke
Markus
----------------------------------------------------------------------------------
Als Hibernate Sessionfactory verwende ich den folgenden Code aus einem Tutorial
----------------------------------------------------------------------------------
public class HSfab {
private static String CONFIG_FILE_LOCATION = "db_model/mapping/hibernate.cfg.xml";
private static final ThreadLocal threadLocal = new ThreadLocal();
private static final Configuration cfg = new Configuration();
private static SessionFactory sessionFactory;
private static Logger logger = Logger.getLogger("db_model.HAfab");
public static Session currentSession() throws HibernateException {
Session session = (Session) threadLocal.get();
if (session == null || ! session.isConnected()) {
if (sessionFactory == null) {
try {
cfg.configure(CONFIG_FILE_LOCATION);
sessionFactory = cfg.buildSessionFactory();
}
catch (Exception e) {
System.err.println("%%%% Error Creating SessionFactory %%%%" +e.getMessage());
e.printStackTrace();
}
}
session = sessionFactory.openSession();
threadLocal.set(session);
}
return session;
}
public static void closeSession() throws HibernateException {
Session session = (Session) threadLocal.get();
threadLocal.set(null);
if (session != null) {
session.close();
}
}
private HSfab() {
}
}
----------------------------------------------------------------------------------
Die Methode, bei der der Crash passiert
----------------------------------------------------------------------------------
public List getAllModules(){
session = HSfab.currentSession();
trans = session.beginTransaction();
List xxx = null;
try{
String query = "from Module";
xxx = session.createQuery(query).list();
trans.commit();
}
catch(Exception e){
trans.rollback();
}
finally{
HSfab.closeSession();
}
return xxx;
}
----------------------------------------------------------------------------------
Und hier der Stacktrace
----------------------------------------------------------------------------------
65401674 [http-8080-Processor24] INFO db_model.GetData - ****************** GetData.getAllModules()
65401674 [http-8080-Processor24] INFO db_model.HAfab - Step 1
65401674 [http-8080-Processor24] INFO db_model.HAfab - Step 2
65401674 [http-8080-Processor24] INFO db_model.HAfab - Step 5
65401674 [http-8080-Processor24] INFO db_model.GetData - session.isConnected: true
65401674 [http-8080-Processor24] INFO db_model.GetData - Transaktion.isActive: true
65402170 [http-8080-Processor24] WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 0, SQLState: 08S01
65402170 [http-8080-Processor24] ERROR org.hibernate.util.JDBCExceptionReporter - Communications link failure due to underlying exception:
** BEGIN NESTED EXCEPTION **
java.net.SocketException
MESSAGE: Broken pipe
STACKTRACE:
java.net.SocketException: Broken pipe
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65)
at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:123)
at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:2690)
at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:2619)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1552)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1666)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2978)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2902)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:933)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1027)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:120)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1272)
at org.hibernate.loader.Loader.doQuery(Loader.java:391)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
at org.hibernate.loader.Loader.doList(Loader.java:1593)
at org.hibernate.loader.Loader.list(Loader.java:1577)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:395)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:271)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:844)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at db_model.GetData.getAllModules(GetData.java:104)
at model.Model.getSystemConfiguration(Model.java:89)
at logic.RuleEngine.<init>(RuleEngine.java:63)
at gui.controller.GuiController.setRelease(GuiController.java:72)
at gui.actions.FeatureSelectAction.firstInit(FeatureSelectAction.java:74)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:280)
at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:216)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)
** END NESTED EXCEPTION **
Last packet sent to the server was 15 ms ago.
65402185 [http-8080-Processor24] INFO db_model.GetData - Fehler in get AllModules-> could not execute query
65402228 [http-8080-Processor24] ERROR org.hibernate.transaction.JDBCTransaction - JDBC rollback failed
java.sql.SQLException: 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.net.SocketException
MESSAGE: Broken pipe
|