Is it possible for two database connections to have different Entities in a bundle? If so, why I still got errors?
Goal: Is to have two connections that can be pass to Resource files and do a decision there whether to use mssql or Postgres, depends on the client request: *Sample Client request:* *1.* Request for mssql database connection curl --location --request GET 'http://localhost:8080/version?db=mssql' \ --header 'Authorization: Bearer i82mL..xUwBABLTYfsqa0wbAOVknpOQrtDHL' *1. *Request for Postgres database connection curl --location --request GET 'http://localhost:8080/version?db=mssql' \ --header 'Authorization: Bearer i82mL..xUwBABLTYfsqa0wbAOVknpOQrtDHL' *Resource Logic:* @GET @Operation(description = "This endpoint used to get the current version of EpochServer") public VersionInfo getVersion(@NotBlank @QueryParam("db") String db) { if(db.equals("mssql")) { versionInfo.setNeedToUseDatabase("using mssql"); DataSourceFactory mssql = configuration.getMSSQLDataSourceFactory(); } else { versionInfo.setNeedToUseDatabase("using postgres"); DataSourceFactory postgres = configuration.getPostgresDataSourceFactory(); } return versionInfo; } *Error:* java.lang.IllegalArgumentException: A health check named hibernate already exists at com.codahale.metrics.health.HealthCheckRegistry.register(HealthCheckRegistry.java:101) at io.dropwizard.hibernate.HibernateBundle.run(HibernateBundle.java:77) at io.dropwizard.setup.Bootstrap.run(Bootstrap.java:199) at io.dropwizard.cli.EnvironmentCommand.run(EnvironmentCommand.java:58) at io.dropwizard.cli.ConfiguredCommand.run(ConfiguredCommand.java:98) at io.dropwizard.cli.Cli.run(Cli.java:78) at io.dropwizard.Application.run(Application.java:94) *Code snippet:* private final HibernateBundle<TardisConfiguration> hibernate = new ScanningHibernateBundle<TardisConfiguration>(new String[] {"com.my.package.hibernateEntities.mssql"}, new SessionFactoryFactory()) { @Override public DataSourceFactory getDataSourceFactory(TardisConfiguration configuration) { return configuration.getDatabase(); } }; private final HibernateBundle<TardisConfiguration> hibernatePostgres = new ScanningHibernateBundle<TardisConfiguration>(new String[] {"com.my.package.hibernateEntities.postgres"}, new SessionFactoryFactory()) { @Override public DataSourceFactory getDataSourceFactory(TardisConfiguration configuration) { return configuration.getDatabase(); } }; *Then in initialize:* @Override public void initialize(Bootstrap<TardisConfiguration> bootstrap) { // wraps exceptions bootstrap.addBundle(hibernate); bootstrap.addBundle(hibernatePostgres); } Thanks, Dondell -- You received this message because you are subscribed to the Google Groups "dropwizard-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/dropwizard-user/700f013a-ee31-40b0-8a1e-ce4db678dc4bn%40googlegroups.com.
