There is no problem with jpa accessing third-party database reports (the table actually exists)

Problem Description:

During the development process of our project, we used jpa to query non-local libraries and used native sql to query third-party databases.

For example:

@DS("配置的库名")
@Query(value = " select 字段1,字段2 from table",nativeQuery = true)
List<Map<String,接受字段对象>> getXXXList();

During the program calling process, the report always did not exist, but the related tables could be seen in plsql. I always thought that the jpa syntax problem was written, but finally found that it was caused by a transaction problem.

Solution:

We remove transaction annotations at the service implementation layer.

reason:

The way we use multi-data is the multi-data source configuration that comes with spring

spring:

        datasource:

                primary:baseA #Default database

                strict: false #Whether to strictly match the database

                datasource:

                        baseA:

                                url:

                                username:

                                wait

                        baseB:

                                url:

                                username:

                                wait

Because of the use of transactional transaction annotations,

The default main data source is used. Even if I use DS ("baseB"), I can't find the third-party database.

In the past, when we configured multiple data sources, we wrote two config configuration classes respectively. When the project started, we loaded two config files, loaded two databases, and interacted with the databases in different folders. There was no such problem. This is quite special. record it

おすすめ

転載: blog.csdn.net/qq_44691484/article/details/128557607