You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by tonywestonuk <to...@totspics.com> on 2017/05/22 09:16:19 UTC

Correct destroy of producer method.

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.

Re: Correct destroy of producer method.

Posted by tonywestonuk <to...@totspics.com>.
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




--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/Correct-destroy-of-producer-method-tp4681721p4681724.html
Sent from the TomEE Users mailing list archive at Nabble.com.

Re: Correct destroy of producer method.

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Do you use context.xml? If so maybe use tomee.xml

Le 22 mai 2017 05:30, "tonywestonuk" <to...@totspics.com> 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.
>