1

I am developing my first micronaut application and i'm having a problem configuring oracle multiple datasources with ucp.

I'm following the oficial tutorial (https://micronaut-projects.github.io/micronaut-sql/latest/guide/) by when I try to perform a select, I get a error:

io.micronaut.transaction.jdbc.exceptions.CannotGetJdbcConnectionException: No current JDBC Connection found. Consider wrapping this call in transactional boundaries.

I check the DataSourceFactory and the PoolDataSource is set correctly

What am I missing?

Thanks!

micronaut:
  application:
    name: myapp
datasources:
  first: 
    url: url
    connectionFactoryClassName: oracle.jdbc.pool.OracleDataSource
    username: user
    password: password
    minPoolSize: 1
    maxPoolSize: 10
  second: 
    url: url
    connectionFactoryClassName: oracle.jdbc.pool.OracleDataSource
    username: user
    password: password
    minPoolSize: 1
    maxPoolSize: 10

@JdbcRepository(dialect = Dialect.ORACLE)
public abstract class MyRepository {

@Inject
@Named("first")
protected final DataSource dataSource;

protected final JdbcOperations jdbcOperations;

public MyRepository(JdbcOperations jdbcOperations, DataSource dataSource) {
    this.dataSource = dataSource;
    this.jdbcOperations = jdbcOperations;
}
}

@Singleton
public class MyDao extends MyRepository {

    public MyDao(JdbcOperations jdbcOperations, DataSource dataSource) {
        super(jdbcOperations, dataSource);
    }

    @Transactional
    public Long find() {
        String sql = "select * from table where id = 1";
        return this.jdbcOperations.prepareStatement(sql, st -> {
            return 1L;
        });

}
  • Is this exactly the file you use? Because there are some dummy Variables like 'datasources.first.url' – Mafick May 15 '20 at 08:48
  • No @Mafick. Is just to ilustrate my problem. I don't know what i'm missing to perform a simple select on my Oracle database. – Thiago Di Santi May 15 '20 at 13:24
  • Is this here what you are looking for? https://guides.micronaut.io/micronaut-data-access-jpa-hibernate/guide/index.html – Mafick May 16 '20 at 16:57
  • @Mafick I don't want use Hibernate ou JPA. I've created an github account and a repo with a single ucp datasource to ilustrate my problem: https://github.com/tdisanti/micronaut-single-ucp. It's working perfectly and what I need is a multiple datasource. I want to perform some operations to multiple oracle databases. Thank you. – Thiago Di Santi May 18 '20 at 13:30
  • @Thiago Di Santi: did you find the solution, i am also looking for the solutions. – 2787184 Jul 13 '20 at 10:01
  • @2787184 No. Unfortunately, I didn't find the solution. I had to leave this experimental project for a while and I'll probably try in a near future. I you find the solution, please let me know! I really want to try Micronaut. – Thiago Di Santi Jul 14 '20 at 14:50
  • @ThiagoDiSanti Please find the answer on https://stackoverflow.com/questions/62797107/micronaut-data-multiple-data-sources/62894430#62894430, i tried and it worked for me. – 2787184 Jul 15 '20 at 03:38

1 Answers1

0

The first datasource needs to be called 'default'. Also when using a transaction with the non-default datasource, you need to use @TransactionAdvice with the datasource name, e.g. @TransactionalAdvice("Second").

PhilBa
  • 732
  • 4
  • 16