0

For a project on which we do not have control over the structure of the database which is denormalized, we must query tables whose name contains country search criteria such as :

  • PRODUCT_FR
  • PRODUCT_ES
  • PRODUCT_GB

Does Spring Data Jdbc support dynamic table names? And how ?

user3849838
  • 113
  • 9

1 Answers1

1

It currently doesn't because SQL Statements get cached. But there is an issue that would enable that https://github.com/spring-projects/spring-data-jdbc/issues/435

Jens Schauder
  • 77,657
  • 34
  • 181
  • 348
  • Is it possible to use NamingStrategy to generate dynamic table name based on context ? – user3849838 Jan 21 '21 at 08:47
  • As written in the answer and in the referenced issue: No, SQL statements currently get cached and therefore the `NamingStrategy` gets consulted only once. – Jens Schauder Jan 21 '21 at 08:50
  • I think we will be forced to use MyBatis for our use case even if we are very seduced by this new Spring Data JDBC brick. What do you think about? Or do you think Spring Data JDBC + MyBatis integration could do the job? – user3849838 Jan 21 '21 at 08:57
  • If you have other parts, that would benefit from Spring Data JDBC try the MyBatis integration. If not, MyBatis sounds reasonable. There is also another option of providing a PR for the issue ... – Jens Schauder Jan 21 '21 at 09:25
  • I read https://docs.spring.io/spring-data/jdbc/docs/current/reference/html/#jdbc.mybatis. It seems that MyBatis only supports Spring Data JDBC CrudRepository queries and not necessarily yet derived queries? Do you confirm ? – user3849838 Jan 21 '21 at 10:37