Brian,

you are supposed to be calling Database.commit()/rollback() before
trying to close the Database instance.

Werner

Brian Schlining wrote:
> I've updated my application to Castor-0.9.9.1 and am having issues  with
> Database.getJdbcConnection(). No matter how I try to use the  connection
> I get one of 2 errors:
> 1) If I don't call database.begin() (which I wasn't in castor-0.9.9) 
> then I getan org.exolab.castor.jdo.PersistenceException: "JDBC usage 
> caused an error: No transaction in progress for the current thread. 
> Please start a transaction before trying to obtain the JDBC connection"
> 2) If I do call database.begin() I get an 
> org.exolab.castor.jdo.PersistenceException: "The database had an open 
> transaction -- transaction rolledback" when I call database.close()
> 
> If I don't close the database everything proceeds fine. I don't  believe
> this is the desired behavior. Any ideas or suggestions?
> 
> Here's a unit test of how I am trying to use it:
> 
> import java.sql.Connection;
> import java.sql.DatabaseMetaData;
> 
> import junit.framework.Test;
> import junit.framework.TestCase;
> import junit.framework.TestSuite;
> import junit.textui.TestRunner;
> 
> import org.exolab.castor.jdo.Database;
> import org.exolab.castor.jdo.JDOManager;
> import org.exolab.castor.jdo.PersistenceException;
> import org.exolab.castor.mapping.MappingException;
> 
> public class CastorJDBCConnectionTest extends TestCase {
> 
>     private JDOManager jdoManager;
> 
>     /**
>      * Constructor for JdoDatabaseFactoryTest.
>      * @param arg0
>      */
>     public CastorJDBCConnectionTest(String arg0) {
>         super(arg0);
>     }
> 
>     public static Test suite() {
>         return new TestSuite(CastorJDBCConnectionTest.class);
>     }
> 
>     public static void main(String[] args) {
>         TestRunner.run(suite());
>     }
> 
>     public void testJDBCConnection() {
>         String server = null;
>         try {
>             Database database = fetchDatabase();
>             database.begin();
>             Connection connection = database.getJdbcConnection();
>             DatabaseMetaData metadata = connection.getMetaData();
>             server = metadata.getURL();
>             connection.close();
>             database.close();
> 
>         }
>         catch (Exception e) {
>             fail("JDBC usage caused an error. " + e.getClass() + ":  " +
> e.getMessage());
>         }
> 
>         assertNotNull("Failed to get db url", server);
>     }
> 
>     private Database fetchDatabase() throws MappingException, 
> PersistenceException {
>         if (jdoManager == null) {
>             JDOManager.loadConfiguration("vars_database.xml");
>             jdoManager = JDOManager.createInstance("vars");
>         }
>         return jdoManager.getDatabase();
>     }
> 
> }
> 
> ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
> Brian Schlining
> MBARI
> Software Engineer
> [EMAIL PROTECTED]
> (831)775-1855
> http://www.mbari.org/staff/brian
> 
> 
> -------------------------------------------------
> If you wish to unsubscribe from this list, please send an empty message
> to the following address:
> 
> [EMAIL PROTECTED]
> -------------------------------------------------
> 
> 


-------------------------------------------------
If you wish to unsubscribe from this list, please 
send an empty message to the following address:

[EMAIL PROTECTED]
-------------------------------------------------

Reply via email to