5 Replies Latest reply on Oct 1, 2007 8:44 AM by Daniel Zimmermann

    Closing a result set you left open!, MySQL

    Hans-Michael Rupp Novice

      Hi, I am just beginning to experiment with JPA.
      I have jboss-4.2.1.GA and MySQL 5.0.45 community installed and I am using mysql-connector-java-5.0.6 as JDBC driver.


      public class TestBean implements TestRemote {
       EntityManager entityManager;
       public Product addProduct(Product product) {
       return product;
      public class Product implements Serializable {
       private long id;
      <?xml version="1.0" encoding="UTF-8"?>
       <persistence-unit name="ejbbuch">
       <!-- should only be used on drivers after 3.22.1 with "ping" support
       <new-connection-sql>SELECT count(*) FROM product</new-connection-sql>
       <check-valid-connection-sql>SELECT count(*) FROM product</check-valid-connection-sql>

      I get the following exceptions in the log file:

      2007-09-28 13:41:04,265 WARN [org.jboss.resource.adapter.jdbc.WrappedConnection] Closing a result set you left open! Please close it yourself.
      java.lang.Throwable: STACKTRACE
       at org.jboss.resource.adapter.jdbc.WrappedStatement.registerResultSet(WrappedStatement.java:617)
       at org.jboss.resource.adapter.jdbc.WrappedStatement.getGeneratedKeys(WrappedStatement.java:533)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

      When I switch back to the DefaultDS (HSQL) this disappears.

      Otherwise the code works as expected with the MySQL database. But of course in a production environment you would not want to force JBoss to handle unclosed statements or resultsets.

      Is this some problem with the JDBC driver or do I have some bug in my code?



        • 1. Re: Closing a result set you left open!, MySQL
          Daniel Zimmermann Newbie

          Hello Marcus,

          unfortunately I cannot help you with your Problem, but maybe you can give me an Advise how to bound MySQL.

          I tried to do a working mysqlds, but it doesn't work...

          What have you done? I would be glad to have your problems :-/


          • 2. Re: Closing a result set you left open!, MySQL
            Hans-Michael Rupp Novice

            Hi BGMF,

            1. Download a JDBC driver from the MySQL site.
            and put it into the lib or deploy directory of your server configuration.
            2. Copy <JBoss_Home>\docs\examples\jca\mysql-ds.xml to your deploy directory and adjust it. Basically you simply have to adjust the connection url, driver-class, user-name and password.
            If user-name or password are wrong you might get a funny exception about the wrong Hibernate dialect which can be confusing.
            3. The jndi-name of your datasource must be referenced in your persistence.xml file like java:/
            Basically all the code to make this work (except for the problem I have) is listed in my example.

            Hope that helps, otherwise what exactly is your problem?



            • 3. Re: Closing a result set you left open!, MySQL
              Daniel Zimmermann Newbie

              Hi Marcus!

              The funny thing is: I've done excactly all these things.
              Maybe the reason is, because I've done the jdbc-lib also in my eclipse project... Maybe jboss is confused because of duplicate drivers...

              But thank you anyway!!!

              I hope you will find the reason for your problem - I guess it's only a ridiculus little config entry missing or so...

              Good Luck!


              • 4. Re: Closing a result set you left open!, MySQL
                Daniel Zimmermann Newbie

                Thanks for your help - it was a little entry missing causing this problem:

                had forgotten to write java:/MySqlDS in persistence.xml
                instead i've written only MySqlDS

                and there was no DS with such a name...

                Thank you very much!

                Have you allready solved your problem?


                • 5. Re: Closing a result set you left open!, MySQL
                  Daniel Zimmermann Newbie


                  I have no idea, but maybe you should change your persistence xml a little bit
                  I got a error because I had not entered the Hibernate Dialect

                   <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />

                  how do you access those TestBean?

                  I was told to write an extra class with source code like this

                   Properties properties = new Properties();
                   InitialContext iContext = new InitialContext(properties);
                   TologDatabaseQueryResponderRemote remote =
                   (TologDatabaseQueryResponderRemote) iContext.lookup("TologResponderEAR/TologDatabaseQueryResponder/remote");
                   catch ( NamingException e )
                   throw new DatabaseQueryResponderException("NamingException while trying to connect to a remote interface:\n"+e.getLocalizedMessage());

                  But I have to admit, that I also have the next problems - but ok - none of your business - you have your own problems...