Hello,
I have a service that receives an XML file from a socket. As a file is received, a new thread is created to parse the file and stores the results in a MySQL database. I have a test driver that sends 30 XML files across the socket to my sever.
My code checks to see if the data in an XML file already exists in the database. If it does, it loads this record and updates any of the fields sent. Otherwise, it creates a new record.
My setup:
Hibernate 3.1
HibernateSynchronizer .1.1
Java 1.5.0.04
c3p0 0.9.0
MySQL 4.1
My hibernate configuration file:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration
PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory >
<!-- local connection properties -->
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/cStationRIS?zeroDateTimeBehavior=convertToNull</property>
<property name="hibernate.connection.driver_class">org.gjt.mm.mysql.Driver</property>
<property name="hibernate.connection.username">radsight</property>
<property name="hibernate.connection.password">compressusRS</property>
<!--property name="hibernate.connection.pool_size">25</property-->
<property name="hibernate.c3p0.acquire_increment">2</property>
<property name="hibernate.c3p0.idle_test_period">3600</property> <!-- seconds -->
<property name="hibernate.c3p0.max_size">100</property>
<property name="hibernate.c3p0.max_statements">30</property>
<property name="hibernate.c3p0.min_size">10</property>
<property name="hibernate.c3p0.timeout">100</property>
<!--property name="hibernate.c3p0.acquire_increment">2</property-->
<!-- dialect for MySQL -->
<property name="hibernate.show_sql">false</property>
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<!-- several mapping resources here -->
</session-factory>
</hibernate-configuration>
My c3p0 properties file contains the following:
c3p0.acquireRetryDelay=1000
c3p0.acquireRetryAttempts=60
c3p0.breakAfterAcquireFailure=false
The method that saves to the database is:
private int parseAndSaveFacility (Element patient, String filenumStr)
{
FacilityDAO dao = null;
int retVal = -1;
try
{
retVal = FindFacility(patient, filenumStr);
if ( retVal == -1 )
{
_RootDAO.initialize();
dao = new FacilityDAO();
Facility fac = new Facility();
// verify that the facility name is unique
Element facility = DOMUtil.getFirstElement(patient, "Facility");
String facName = DOMUtil.getSimpleElementText(facility, "SendingFacility");
fac.setFacName(facName);
dao.save(fac);
// get the autogenerated ID
retVal = fac.getId().intValue();
dao.getSession().flush();
}
else
{
log.warn("File number: " + filenumStr + ", " + "Facility: duplicate");
}
dao.closeCurrentThreadSessions();
}
catch(Exception e)
{
log.error("File number: " + filenumStr + ", " + "parseAndSaveFacility: " + e.getMessage());
}
if (dao != null)
dao.getSession().close();
return retVal;
}
The code for the FindFacility method is:
private int FindFacility (Element patient, String filenumStr)
{
int retVal = -1;
Session session = null;
try
{
_RootDAO.initialize();
FacilityDAO dao = new FacilityDAO();
Facility fac = new Facility();
// verify that the facility name is unique
Element facility = DOMUtil.getFirstElement(patient, "Facility");
String facName = DOMUtil.getSimpleElementText(facility, "SendingFacility");
String query = "select fac.Id from Facility as fac where fac.FacName = '" + facName + "'";
session = dao.getSession();
List list = session.createQuery(query).list();
int numOfRecords = list.size();
if (numOfRecords > 0)
{
// duplicate entry - get the corresponding ID
retVal = ((Integer)list.get(0)).intValue();
log.warn("File number: " + filenumStr + ", " + "Facility: " + facName + " exist");
}
dao.closeCurrentThreadSessions();
}
catch(Exception e)
{
log.error("File number: " + filenumStr + ", " + "FindFacility: " + e.getMessage());
retVal = -1;
}
if (session != null)
{
session.close();
session = null;
}
return retVal;
}
The logged error:
2005-10-12 20:13:30,970 WARN [org.hibernate.util.JDBCExceptionReporter] SQL Error: 1062, SQLState: 23000
2005-10-12 20:13:30,970 ERROR [org.hibernate.util.JDBCExceptionReporter] Duplicate entry 'MyCity' for key 2
2005-10-12 20:13:30,970 ERROR [ca.uhn.hl7v2.parser.MCPatientListParser] File number: 0, parseAndSaveFacility: could not insert: [ca.uhn.hl7v2.hibernate.Facility]
2005-10-12 20:13:30,990 WARN [org.hibernate.util.JDBCExceptionReporter] SQL Error: 1062, SQLState: 23000
2005-10-12 20:13:31,080 ERROR [org.hibernate.util.JDBCExceptionReporter] Duplicate entry 'MyCity' for key 2
2005-10-12 20:13:31,080 ERROR [ca.uhn.hl7v2.parser.MCPatientListParser] File number: 2, parseAndSaveFacility: could not insert: [ca.uhn.hl7v2.hibernate.Facility]
2005-10-12 20:13:32,481 WARN [ca.uhn.hl7v2.parser.MCPatientListParser] File number: 5, Facility: MyCity exist
2005-10-12 20:13:32,481 WARN [ca.uhn.hl7v2.parser.MCPatientListParser] File number: 5, Facility: duplicate
2005-10-12 20:13:32,481 WARN [ca.uhn.hl7v2.parser.MCPatientListParser] File number: 5, Patient status: null
2005-10-12 20:13:32,602 WARN [ca.uhn.hl7v2.parser.MCPatientListParser] File number: 7, Facility: MyCity exist
2005-10-12 20:13:32,602 WARN [ca.uhn.hl7v2.parser.MCPatientListParser] File number: 7, Facility: duplicate
2005-10-12 20:13:32,602 WARN [ca.uhn.hl7v2.parser.MCPatientListParser] File number: 7, Patient status: null
2005-10-12 20:13:34,514 WARN [ca.uhn.hl7v2.parser.MCPatientListParser] File number: 6, Facility: MyCity exist
2005-10-12 20:13:34,514 WARN [ca.uhn.hl7v2.parser.MCPatientListParser] File number: 6, Facility: duplicate
2005-10-12 20:13:34,514 WARN [ca.uhn.hl7v2.parser.MCPatientListParser] File number: 6, Patient status: discharged
2005-10-12 20:13:34,514 WARN [ca.uhn.hl7v2.parser.MCPatientListParser] File number: 4, Facility: MyCity exist
2005-10-12 20:13:34,514 WARN [ca.uhn.hl7v2.parser.MCPatientListParser] File number: 4, Facility: duplicate
2005-10-12 20:13:34,514 WARN [ca.uhn.hl7v2.parser.MCPatientListParser] File number: 4, Patient status: null
2005-10-12 20:13:35,655 WARN [ca.uhn.hl7v2.parser.MCPatientListParser] File number: 14, Facility: MyCity exist
2005-10-12 20:13:35,655 WARN [ca.uhn.hl7v2.parser.MCPatientListParser] File number: 14, Facility: duplicate
2005-10-12 20:13:35,655 WARN [ca.uhn.hl7v2.parser.MCPatientListParser] File number: 14, Patient status: null
2005-10-12 20:13:35,735 WARN [ca.uhn.hl7v2.parser.MCPatientListParser] File number: 8, Facility: MyCity exist
2005-10-12 20:13:35,735 WARN [ca.uhn.hl7v2.parser.MCPatientListParser] File number: 8, Facility: duplicate
2005-10-12 20:13:35,735 WARN [ca.uhn.hl7v2.parser.MCPatientListParser] File number: 8, Patient status: admitted
2005-10-12 20:13:35,805 WARN [ca.uhn.hl7v2.parser.MCPatientListParser] File number: 10, Facility: MyCity exist
2005-10-12 20:13:35,805 WARN [ca.uhn.hl7v2.parser.MCPatientListParser] File number: 10, Facility: duplicate
2005-10-12 20:13:35,805 WARN [ca.uhn.hl7v2.parser.MCPatientListParser] File number: 10, Patient status: discharged
2005-10-12 20:13:36,015 WARN [ca.uhn.hl7v2.parser.MCPatientListParser] File number: 25, Facility: MyCity exist
2005-10-12 20:13:36,015 WARN [ca.uhn.hl7v2.parser.MCPatientListParser] File number: 25, Facility: duplicate
2005-10-12 20:13:36,015 WARN [ca.uhn.hl7v2.parser.MCPatientListParser] File number: 25, Patient status: null
2005-10-12 20:13:36,035 WARN [ca.uhn.hl7v2.parser.MCPatientListParser] File number: 22, Facility: MyCity exist
2005-10-12 20:13:36,035 WARN [ca.uhn.hl7v2.parser.MCPatientListParser] File number: 22, Facility: duplicate
2005-10-12 20:13:36,035 WARN [ca.uhn.hl7v2.parser.MCPatientListParser] File number: 22, Patient status: null
2005-10-12 20:13:36,055 WARN [ca.uhn.hl7v2.parser.MCPatientListParser] File number: 23, Facility: MyCity exist
2005-10-12 20:13:36,055 WARN [ca.uhn.hl7v2.parser.MCPatientListParser] File number: 23, Facility: duplicate
2005-10-12 20:13:36,055 WARN [ca.uhn.hl7v2.parser.MCPatientListParser] File number: 23, Patient status: null
2005-10-12 20:13:36,086 WARN [ca.uhn.hl7v2.parser.MCPatientListParser] File number: 9, Facility: MyCity exist
2005-10-12 20:13:36,086 WARN [ca.uhn.hl7v2.parser.MCPatientListParser] File number: 9, Facility: duplicate
2005-10-12 20:13:36,086 WARN [ca.uhn.hl7v2.parser.MCPatientListParser] File number: 9, Patient status: null
2005-10-12 20:13:36,126 WARN [ca.uhn.hl7v2.parser.MCPatientListParser] File number: 18, Facility: MyCity exist
2005-10-12 20:13:36,126 WARN [ca.uhn.hl7v2.parser.MCPatientListParser] File number: 18, Facility: duplicate
2005-10-12 20:13:36,126 WARN [ca.uhn.hl7v2.parser.MCPatientListParser] File number: 18, Patient status: null
2005-10-12 20:13:36,146 WARN [ca.uhn.hl7v2.parser.MCPatientListParser] File number: 27, Facility: MyCity exist
2005-10-12 20:13:36,146 WARN [ca.uhn.hl7v2.parser.MCPatientListParser] File number: 27, Facility: duplicate
2005-10-12 20:13:36,146 WARN [ca.uhn.hl7v2.parser.MCPatientListParser] File number: 27, Patient status: discharged
2005-10-12 20:13:36,156 WARN [ca.uhn.hl7v2.parser.MCPatientListParser] File number: 13, Facility: MyCity exist
2005-10-12 20:13:36,176 WARN [ca.uhn.hl7v2.parser.MCPatientListParser] File number: 13, Facility: duplicate
2005-10-12 20:13:36,176 WARN [ca.uhn.hl7v2.parser.MCPatientListParser] File number: 13, Patient status: null
2005-10-12 20:13:36,226 WARN [ca.uhn.hl7v2.parser.MCPatientListParser] File number: 3, Facility: MyCity exist
2005-10-12 20:13:36,236 WARN [ca.uhn.hl7v2.parser.MCPatientListParser] File number: 12, Facility: MyCity exist
2005-10-12 20:13:36,236 WARN [ca.uhn.hl7v2.parser.MCPatientListParser] File number: 3, Facility: duplicate
2005-10-12 20:13:36,236 WARN [ca.uhn.hl7v2.parser.MCPatientListParser] File number: 3, Patient status: null
2005-10-12 20:13:36,236 WARN [ca.uhn.hl7v2.parser.MCPatientListParser] File number: 12, Facility: duplicate
2005-10-12 20:13:36,236 WARN [ca.uhn.hl7v2.parser.MCPatientListParser] File number: 12, Patient status: admitted
2005-10-12 20:13:36,246 WARN [ca.uhn.hl7v2.parser.MCPatientListParser] File number: 19, Facility: MyCity exist
2005-10-12 20:13:36,266 WARN [ca.uhn.hl7v2.parser.MCPatientListParser] File number: 28, Facility: MyCity exist
2005-10-12 20:13:36,286 WARN [ca.uhn.hl7v2.parser.MCPatientListParser] File number: 20, Facility: MyCity exist
2005-10-12 20:13:36,286 WARN [ca.uhn.hl7v2.parser.MCPatientListParser] File number: 24, Facility: MyCity exist
2005-10-12 20:13:36,296 WARN [ca.uhn.hl7v2.parser.MCPatientListParser] File number: 19, Facility: duplicate
2005-10-12 20:13:36,296 WARN [ca.uhn.hl7v2.parser.MCPatientListParser] File number: 20, Facility: duplicate
2005-10-12 20:13:36,296 WARN [ca.uhn.hl7v2.parser.MCPatientListParser] File number: 24, Facility: duplicate
2005-10-12 20:13:36,296 WARN [ca.uhn.hl7v2.parser.MCPatientListParser] File number: 28, Facility: duplicate
2005-10-12 20:13:36,296 WARN [ca.uhn.hl7v2.parser.MCPatientListParser] File number: 19, Patient status: discharged
2005-10-12 20:13:36,296 WARN [ca.uhn.hl7v2.parser.MCPatientListParser] File number: 20, Patient status: non-admitted
2005-10-12 20:13:36,296 WARN [ca.uhn.hl7v2.parser.MCPatientListParser] File number: 24, Patient status: discharged
2005-10-12 20:13:36,296 WARN [ca.uhn.hl7v2.parser.MCPatientListParser] File number: 28, Patient status: non-admitted
2005-10-12 20:14:33,460 WARN [com.mchange.v2.resourcepool.BasicResourcePool] com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@1c4bcda -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (60).
2005-10-12 20:14:33,470 WARN [org.hibernate.cfg.SettingsFactory] Could not obtain connection metadata
java.sql.SQLException: Connections could not be acquired from the underlying database!
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:104)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:236)
at com.mchange.v2.c3p0.PoolBackedDataSource.getConnection(PoolBackedDataSource.java:94)
at org.hibernate.connection.C3P0ConnectionProvider.getConnection(C3P0ConnectionProvider.java:35)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:72)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1815)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1143)
at ca.uhn.hl7v2.hibernate.base._BaseRootDAO.initialize(_BaseRootDAO.java:54)
at ca.uhn.hl7v2.hibernate.base._BaseRootDAO.initialize(_BaseRootDAO.java:41)
at ca.uhn.hl7v2.hibernate.base._BaseRootDAO.initialize(_BaseRootDAO.java:32)
at ca.uhn.hl7v2.parser.MCPatientListParser.FindFacility(MCPatientListParser.java:335)
at ca.uhn.hl7v2.parser.MCPatientListParser.parseAndSaveFacility(MCPatientListParser.java:582)
at ca.uhn.hl7v2.parser.MCPatientListParser.addOrUpdate(MCPatientListParser.java:271)
at ca.uhn.hl7v2.parser.MCPatientListParser.parseAndSave(MCPatientListParser.java:99)
at ca.uhn.hl7v2.parser.MCPatientListParser.parseAndSave(MCPatientListParser.java:73)
at ca.uhn.hl7v2.app.Receiver.processMessage(Receiver.java:127)
at ca.uhn.hl7v2.app.Receiver.run(Receiver.java:70)
at java.lang.Thread.run(Unknown Source)
Caused by: com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.
at com.mchange.v2.resourcepool.BasicResourcePool.awaitAcquire(BasicResourcePool.java:970)
at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:208)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:232)
... 16 more
2005-10-12 20:14:33,470 ERROR [ca.uhn.hl7v2.parser.MCPatientListParser] File number: 26, FindFacility: Hibernate Dialect must be explicitly set
2005-10-12 20:14:33,480 WARN [org.hibernate.util.JDBCExceptionReporter] SQL Error: 1062, SQLState: 23000
2005-10-12 20:14:33,480 ERROR [org.hibernate.util.JDBCExceptionReporter] Duplicate entry 'MyCity' for key 2
2005-10-12 20:14:33,480 ERROR [ca.uhn.hl7v2.parser.MCPatientListParser] File number: 26, parseAndSaveFacility: could not insert: [ca.uhn.hl7v2.hibernate.Facility]
2005-10-12 20:14:33,530 WARN [com.mchange.v2.resourcepool.BasicResourcePool] com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@1fddb33 -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (60).
2005-10-12 20:14:33,540 WARN [com.mchange.v2.resourcepool.BasicResourcePool] com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@141fc8c -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (60).
2005-10-12 20:14:33,540 WARN [org.hibernate.cfg.SettingsFactory] Could not obtain connection metadata
java.sql.SQLException: Connections could not be acquired from the underlying database!
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:104)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:236)
at com.mchange.v2.c3p0.PoolBackedDataSource.getConnection(PoolBackedDataSource.java:94)
at org.hibernate.connection.C3P0ConnectionProvider.getConnection(C3P0ConnectionProvider.java:35)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:72)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1815)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1143)
at ca.uhn.hl7v2.hibernate.base._BaseRootDAO.initialize(_BaseRootDAO.java:54)
at ca.uhn.hl7v2.hibernate.base._BaseRootDAO.initialize(_BaseRootDAO.java:41)
at ca.uhn.hl7v2.hibernate.base._BaseRootDAO.initialize(_BaseRootDAO.java:32)
at ca.uhn.hl7v2.parser.MCPatientListParser.FindFacility(MCPatientListParser.java:335)
at ca.uhn.hl7v2.parser.MCPatientListParser.parseAndSaveFacility(MCPatientListParser.java:582)
at ca.uhn.hl7v2.parser.MCPatientListParser.addOrUpdate(MCPatientListParser.java:271)
at ca.uhn.hl7v2.parser.MCPatientListParser.parseAndSave(MCPatientListParser.java:104)
at ca.uhn.hl7v2.parser.MCPatientListParser.parseAndSave(MCPatientListParser.java:73)
at ca.uhn.hl7v2.app.Receiver.processMessage(Receiver.java:127)
at ca.uhn.hl7v2.app.Receiver.run(Receiver.java:70)
at java.lang.Thread.run(Unknown Source)
Caused by: com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.
at com.mchange.v2.resourcepool.BasicResourcePool.awaitAcquire(BasicResourcePool.java:970)
at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:208)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:232)
... 16 more
<many more of the same warnings and errors>
I also tried the same configuration file with hibernate.c3p0.max_statements = 0
Either way I get the same problem.
I would truly appreciate any help. I have been looking for help through this forum and other sources for couple of days now and have tried the recommended solutions but no luck.
Thanks a lot in advance.
_________________ patches
|