0

I understand some of the benefits with using Spring's JPA such as taking advantage of Crud and JPA repository functions to effortlessly access a data source. This seems lost when multiple data sources are to be used. I've seen various examples on how to do this, but the added time to create a bunch of classes for each data source seems excessive.

Why should we take the time to use Spring's JPA to configure multiple data sources when can just use POJO methods?

Thanks.

proximityFlying
  • 153
  • 3
  • 13
  • What do multiple data sources have to do with pojo methods? I was following you right up until the question itself. For what it's worth I use dynamic data sources so I can connect to any of my hundreds of customer databases at will; 2 classes and a custom configuration class ... easy peasy. – Roddy of the Frozen Peas Mar 20 '19 at 19:53
  • In plain old java objects that say uses a swing user interface I would create connections to databases with Connection, DriverManager, PreparedStatement, and ResultSet classes. – proximityFlying Mar 20 '19 at 20:06
  • Spring and JPA abstract all that away regardless of how many data sources you have so I'm still unclear really what the question is – Roddy of the Frozen Peas Mar 20 '19 at 20:47
  • Could you clarify which parts of Spring you are referring to? There is spring-jdbc, spring-orm, spring-data-jpa, spring-data-jdbc and maybe even spring-boot that might be relevant here. The only part that seems lost when using multiple datasources is spring boots autoconfiguration. It's a long way from any variant of Spring + JPA to working with ResultSets directly again. – Jens Schauder Mar 21 '19 at 07:16
  • Related at least as far as the question in the title goes: https://stackoverflow.com/questions/42470060/spring-data-jdbc-spring-data-jpa-vs-hibernate/42488593 – Jens Schauder Feb 13 '20 at 09:25

1 Answers1

1

JPA also abstracts you from the implementation and store engine with different dialects. You can add abstraction layers on top of it to abstract from the actual different datasources, although I don't think the schema is shared, so you endup needing pojos in any case as dtos.

What do you mean by POJO methods?

Anyway, I don't think this is a question for stack overflow

Juan Carrey
  • 696
  • 1
  • 6
  • 13
  • In plain old java objects that say uses a swing user interface I would create connections to databases with Connection, DriverManager, PreparedStatement, and ResultSet classes. – proximityFlying Mar 20 '19 at 20:15