Skip to content

Connection closed issue #90

@lindholm

Description

@lindholm

I've put together a small utility library to help our local code base unit test
our beans and such.
But for some reason when I'm using derby and hibernate, I get these errors:

checkBeanEm(ca.ubc.sis.test.arquillian.TestArquillianDerbyTest)  Time elapsed: 0.014 sec  <<< ERROR!
org.jboss.arquillian.persistence.dbunit.exception.DBUnitDataSetHandlingException: Failed while seeding database.
Caused by: org.dbunit.dataset.DataSetException: Exception while searching the dependent tables.
Caused by: org.dbunit.util.search.SearchException: java.sql.SQLException: Connection jdbc:derby:memory:testDB, UserName=SA, Apache Derby Embedded JDBC Driver is closed.
Caused by: java.sql.SQLException: Connection jdbc:derby:memory:testDB, UserName=SA, Apache Derby Embedded JDBC Driver is closed.

After a lot of poking around I came up with this fix:

diff --git a/dbunit/src/main/java/org/jboss/arquillian/persistence/dbunit/DBUnitPersistenceTestLifecycleHandler.java b/dbunit/src/main/java/org/jboss/arquillian/persistence/dbunit/DBUnitPersistenceTestLifecycleHandler.java
index 28bc80e..0223461 100644
--- a/dbunit/src/main/java/org/jboss/arquillian/persistence/dbunit/DBUnitPersistenceTestLifecycleHandler.java
+++ b/dbunit/src/main/java/org/jboss/arquillian/persistence/dbunit/DBUnitPersistenceTestLifecycleHandler.java
@@ -115,8 +117,12 @@
 
     private void createDatabaseConnection() {
 
-        if (databaseConnectionProducer.get() == null) {
-            configureDatabaseConnection();
+        try {
+            if (databaseConnectionProducer.get() == null || databaseConnectionProducer.get().getConnection().isClosed()) {
+                configureDatabaseConnection();
+            }
+        } catch (SQLException e) {
+            throw new DBUnitInitializationException("Unable to createDatabaseConnection database connection for DBUnit module.", e);
         }
     }
 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions