Correct destroy of producer method.

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Correct destroy of producer method.

tonywestonuk
I have an @ApplicationScoped class containing a producer method....below.

When I start/stop the application with the manager app, I get the error:
javax.management.InstanceAlreadyExistsException: tomcat.jdbc:name="org.tony.DBIProducer/dataSource",context=/tribune_etl,engine=Catalina,type=ConnectionPool,host=localhost,class=org.apache.tomcat.jdbc.pool.DataSource


What do I need to do, to avoid this error.
Thanks.



@ApplicationScoped
public class DBIProducer implements ConnectionFactory {
       
        @Resource
        DataSource dataSource;
       
        @Resource(name="db_schema")
        String schema;
       
        @Produces
        public DBI createDBI(){
                DBI dbi = new DBI(this);
               
                return new DBI(this);
        }

       
        @Override
        public Connection openConnection() throws SQLException {
                Connection connection = dataSource.getConnection();
                connection.setSchema(schema);
                connection.setAutoCommit(true);
                return connection;
        }
}


Reply | Threaded
Open this post in threaded view
|

Re: Correct destroy of producer method.

Romain Manni-Bucau
Do you use context.xml? If so maybe use tomee.xml

Le 22 mai 2017 05:30, "tonywestonuk" <[hidden email]> a écrit :

> I have an @ApplicationScoped class containing a producer method....below.
>
> When I start/stop the application with the manager app, I get the error:
> javax.management.InstanceAlreadyExistsException:
> tomcat.jdbc:name="org.tony.DBIProducer/dataSource",
> context=/tribune_etl,engine=Catalina,type=ConnectionPool,
> host=localhost,class=org.apache.tomcat.jdbc.pool.DataSource
>
>
> What do I need to do, to avoid this error.
> Thanks.
>
>
>
> @ApplicationScoped
> public class DBIProducer implements ConnectionFactory {
>
>         @Resource
>         DataSource dataSource;
>
>         @Resource(name="db_schema")
>         String schema;
>
>         @Produces
>         public DBI createDBI(){
>                 DBI dbi = new DBI(this);
>
>                 return new DBI(this);
>         }
>
>
>         @Override
>         public Connection openConnection() throws SQLException {
>                 Connection connection = dataSource.getConnection();
>                 connection.setSchema(schema);
>                 connection.setAutoCommit(true);
>                 return connection;
>         }
> }
>
>
>
>
>
>
> --
> View this message in context: http://tomee-openejb.979440.
> n4.nabble.com/Correct-destroy-of-producer-method-tp4681721.html
> Sent from the TomEE Users mailing list archive at Nabble.com.
>
Reply | Threaded
Open this post in threaded view
|

Re: Correct destroy of producer method.

tonywestonuk
Close....., but you sent me in the right direction!

My postgresql datasource was defined in server.xml, rather than tomee.xml.  Works great now moved to tomee.xml