<takes note of the new format of questions.>
Hi all, been a while since I last visited, but got an interesting little issue, that I believe is NOT Hibernate's fault, but since it involves Hibernate, I figured that I'd at least check with you guys to make sure that I've at least done the Hibernate part right. :)
Hibernate Version: 2.0
I'm not going to post my mapping docs, as I know they are right (quite simple ones), but I'll post the first few lines of my hibernate.cfg.xml files.
This is my cfg for a MYSQL database of version 4.0.17-nt
Code:
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>
And this is my cfg for a MYSQL database of version 3.23.57-nt
Code:
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>
As you can see, they're identical.
Now here's the exception stacktrace, it's rather long, as it's a result of the first one, being caught, and then trying to handle, and that failing too, etc.
Code:
pr 22, 2004 8:03:25 PM net.sf.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 0, SQLState: 08003
Apr 22, 2004 8:03:25 PM net.sf.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: No operations allowed after connection closed
Apr 22, 2004 8:03:25 PM net.sf.hibernate.JDBCException <init>
SEVERE: Could not load object
java.sql.SQLException: No operations allowed after connection closed
at com.mysql.jdbc.Connection.checkClosed(Connection.java:2497)
at com.mysql.jdbc.Connection.prepareStatement(Connection.java:1287)
at com.mysql.jdbc.Connection.prepareStatement(Connection.java:1267)
at net.sf.hibernate.impl.SessionFactoryImpl.getPreparedStatement(SessionFactoryImpl.java:543)
at net.sf.hibernate.impl.BatcherImpl.prepareQueryStatement(BatcherImpl.java:50)
at net.sf.hibernate.loader.Loader.prepareQueryStatement(Loader.java:395)
at net.sf.hibernate.loader.Loader.doFind(Loader.java:118)
at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:479)
at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:37)
at net.sf.hibernate.persister.EntityPersister.load(EntityPersister.java:386)
at net.sf.hibernate.impl.SessionImpl.doLoad(SessionImpl.java:1873)
at net.sf.hibernate.impl.SessionImpl.doLoadByClass(SessionImpl.java:1741)
at net.sf.hibernate.impl.SessionImpl.load(SessionImpl.java:1673)
at dse6.processXML.ProcessXML.doPartyMatter(ProcessXML.java:215)
at dse6.processXML.ProcessXML.saveXML(ProcessXML.java:54)
at dse6.processXML.ProcessXML.xsd(ProcessXML.java:561)
at dse6.processXML.ProcessXML.xsd(ProcessXML.java:539)
at dse6.utility.Transform.xmlTransform(Transform.java:59)
at dse6.DSE6Core.run(DSE6Core.java:90)
at dse6.DSE6Runner$RunDSE6.run(DSE6Runner.java:110)
at java.util.TimerThread.mainLoop(Timer.java:432)
at java.util.TimerThread.run(Timer.java:382)
Apr 22, 2004 8:03:25 PM net.sf.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 0, SQLState: 08003
Apr 22, 2004 8:03:25 PM net.sf.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: No operations allowed after connection closed
Apr 22, 2004 8:03:25 PM net.sf.hibernate.JDBCException <init>
SEVERE: Could not insert
java.sql.SQLException: No operations allowed after connection closed
at com.mysql.jdbc.Connection.checkClosed(Connection.java:2497)
at com.mysql.jdbc.Connection.prepareStatement(Connection.java:1287)
at com.mysql.jdbc.Connection.prepareStatement(Connection.java:1267)
at net.sf.hibernate.impl.SessionFactoryImpl.getPreparedStatement(SessionFactoryImpl.java:543)
at net.sf.hibernate.impl.BatcherImpl.prepareStatement(BatcherImpl.java:46)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:468)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:719)
at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:607)
at dse6.processXML.ProcessXML.doPartyMatter(ProcessXML.java:300)
at dse6.processXML.ProcessXML.saveXML(ProcessXML.java:54)
at dse6.processXML.ProcessXML.xsd(ProcessXML.java:561)
at dse6.processXML.ProcessXML.xsd(ProcessXML.java:539)
at dse6.utility.Transform.xmlTransform(Transform.java:59)
at dse6.DSE6Core.run(DSE6Core.java:90)
at dse6.DSE6Runner$RunDSE6.run(DSE6Runner.java:110)
at java.util.TimerThread.mainLoop(Timer.java:432)
at java.util.TimerThread.run(Timer.java:382)
Apr 22, 2004 8:03:25 PM net.sf.hibernate.transaction.JDBCTransaction rollback
SEVERE: Rollback failed
java.sql.SQLException: No operations allowed after connection closed
at com.mysql.jdbc.Connection.checkClosed(Connection.java:2497)
at com.mysql.jdbc.Connection.rollback(Connection.java:1378)
at net.sf.hibernate.transaction.JDBCTransaction.rollback(JDBCTransaction.java:79)
at dse6.processXML.ProcessXML.doPartyMatter(ProcessXML.java:339)
at dse6.processXML.ProcessXML.saveXML(ProcessXML.java:54)
at dse6.processXML.ProcessXML.xsd(ProcessXML.java:561)
at dse6.processXML.ProcessXML.xsd(ProcessXML.java:539)
at dse6.utility.Transform.xmlTransform(Transform.java:59)
at dse6.DSE6Core.run(DSE6Core.java:90)
at dse6.DSE6Runner$RunDSE6.run(DSE6Runner.java:110)
at java.util.TimerThread.mainLoop(Timer.java:432)
at java.util.TimerThread.run(Timer.java:382)
dse6.utility.IncidentException: net.sf.hibernate.JDBCException: Could not insert: No operations allowed after connection
closed
at dse6.processXML.ProcessXML.doPartyMatter(ProcessXML.java:346)
at dse6.processXML.ProcessXML.saveXML(ProcessXML.java:54)
at dse6.processXML.ProcessXML.xsd(ProcessXML.java:561)
at dse6.processXML.ProcessXML.xsd(ProcessXML.java:539)
at dse6.utility.Transform.xmlTransform(Transform.java:59)
at dse6.DSE6Core.run(DSE6Core.java:90)
at dse6.DSE6Runner$RunDSE6.run(DSE6Runner.java:110)
at java.util.TimerThread.mainLoop(Timer.java:432)
at java.util.TimerThread.run(Timer.java:382)
Here's the code where the error happens, I'll post the Database connectivity bit afterwards.
Code:
session = Database.getSession(DSESettings.getRccName());
tx = session.beginTransaction();
try {
props = matter.getProperties();
for (int i = 0; i < props.getProperty().size(); i++) {
property = (Property) props.getProperty().get(i);
try {
if ((!session.isOpen()) || (!session.isConnected())) {
session.reconnect();
}
tempProp = (Property) session.load(PropertyImpl.class, property.getVALID());
tempProp.setENTITYX(property.getENTITYX());
tempProp.setERFN(property.getERFN());
tempProp.setPRPTYDESCX(property.getPRPTYDESCX());
tempProp.setSTREETADDRESSX(property.getSTREETADDRESSX());
tempProp.setSUBURBX(property.getSUBURBX());
tempProp.setTOWNX(property.getTOWNX());
tempProp.setDeleteFlag(new Integer(0));
session.update(tempProp);
}
catch (JDBCException jdbce) {
newProperty = true;
if ((!session.isOpen()) || (!session.isConnected())) {
session.reconnect();
}
tempProp = property;
tempProp.setDeleteFlag(new Integer(0));
session.save(tempProp);
}
catch (ObjectNotFoundException onfe) {
newProperty = true;
if ((!session.isOpen()) || (!session.isConnected())) {
session.reconnect();
}
tempProp = property;
tempProp.setDeleteFlag(new Integer(0));
session.save(tempProp);
}
catch (HibernateException he) {
newProperty = true;
if ((!session.isOpen()) || (!session.isConnected())) {
session.reconnect();
}
tempProp = property;
tempProp.setDeleteFlag(new Integer(0));
session.save(tempProp);
}
catch (Exception e) {
newProperty = true;
if ((!session.isOpen()) || (!session.isConnected())) {
session.reconnect();
}
tempProp = property;
tempProp.setDeleteFlag(new Integer(0));
session.save(tempProp);
}
valID = tempProp.getVALID();
}
}
catch (NullPointerException npe) {}
And here's the Database bit:
Code:
public static Session getSession(String factory) throws HibernateException {
Session session = null;
if (factory==DSESettings.getRccName()) {
if (rccSessionFactory!=null) {
session = rccSessionFactory.openSession();
}
else {
initialiseSessionFactory(DSESettings.getRccName());
session = rccSessionFactory.openSession();
}
}
else if (factory==DSESettings.getLawnetName()) {
if (lawnetSessionFactory!=null) {
session = lawnetSessionFactory.openSession();
}
else {
initialiseSessionFactory(DSESettings.getLawnetName());
session = lawnetSessionFactory.openSession();
}
}
else if (factory==DSESettings.getFilesName()) {
if (filesSessionFactory!=null) {
session = filesSessionFactory.openSession();
}
else {
initialiseSessionFactory(DSESettings.getFilesName());
session = filesSessionFactory.openSession();
}
}
return session;
}
Now the problem definition. :)
The app that controls this is on a Timer (as you may have noticed from the stacktrace), which wakes up every few minutes and extracts files from one database (ver 3.23), parses them (XML format messages) and then stores them in another database (4.0). The problem seems to occur, that after a prolonged period of no connectivity, the sessionfactory for the RCC database appears to lose all connectivity, i.e. it starts to throw these errors. However, the 3.23 database is continually being accessed by other apps and its connectivity never falters.
Is it possible, that a database can go to "sleep" if it hasn't been accessed for a prolonged period? And how could I get it to wake up. :) Forgive the numerous catch statements, but I've been trying to stop this happening. If I run the same files again after just restarting the app, they run fine, just I'm a little stumped with this one. If it is that the database goes to sleep, I guess I could run a simple query to poll it every few minutes (I'll set this up to run overnight in the mean time).
Thanks for any assistance in advance.
-G