{"id":8307,"date":"2024-09-26T22:32:40","date_gmt":"2024-09-26T17:02:40","guid":{"rendered":"https:\/\/innovationm.co\/?p=8307"},"modified":"2024-09-26T22:35:45","modified_gmt":"2024-09-26T17:05:45","slug":"managing-multiple-databases-in-a-monolithic-spring-boot-app-using-jpa-a-beginners-guide","status":"publish","type":"post","link":"https:\/\/www.innovationm.com\/blog\/managing-multiple-databases-in-a-monolithic-spring-boot-app-using-jpa-a-beginners-guide\/","title":{"rendered":"Managing Multiple Databases in a Monolithic Spring Boot App Using JPA: A Beginner\u2019s Guide"},"content":{"rendered":"<p>In a typical monolithic architecture, applications often interact with a single database. However, there are scenarios where you might need to integrate multiple databases, such as when handling legacy systems or optimizing for performance. With Spring Boot, this is not only possible but can be managed efficiently using DataSource, EntityManager, and TransactionManager.<\/p>\n<p>In this blog, we&#8217;ll walk through how to configure multiple databases in a Spring Boot monolithic application using JPA, covering the complete setup and implementation. Let&#8217;s dive in!<\/p>\n<p><strong>Why Use Multiple Databases in a Monolithic Application?<br \/>\n<\/strong><br \/>\nThere are several use cases where multiple databases might be necessary:<br \/>\n<strong>1. Data Segregation<\/strong>: Separate databases can be used to isolate certain parts of the application (e.g., reporting, user data).<br \/>\n<strong>2. Legacy Integration:<\/strong> You may need to integrate with a legacy system that uses a different database.<br \/>\n<strong>3. Performance Optimization:<\/strong> Splitting data between databases can sometimes help with performance scaling.<\/p>\n<p><strong>Step 1: Add Dependencies<\/strong><br \/>\nTo use multiple databases, you&#8217;ll need to add relevant dependencies to your pom.xml. We\u2019ll<br \/>\nassume you\u2019re using H2 and MySQL for this example.<\/p>\n<p>&lt;dependencies&gt;<br \/>\n&lt;!&#8211; Spring Boot Starter Data JPA &#8211;&gt;<br \/>\n&lt;dependency&gt;<br \/>\n&lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;<br \/>\n&lt;artifactId&gt;spring-boot-starter-data-jpa&lt;\/artifactId&gt;<br \/>\n&lt;\/dependency&gt;<\/p>\n<p>&lt;!&#8211; Spring Boot Starter Web (if you&#8217;re building a web application) &#8211;&gt;<br \/>\n&lt;dependency&gt;<\/p>\n<p>&lt;!&#8211; Add other database drivers as needed, for example:<br \/>\n&lt;!&#8211; PostgreSQL &#8211;&gt;<br \/>\n&lt;!&#8211; &lt;dependency&gt;<br \/>\n&lt;groupId&gt;org.postgresql&lt;\/groupId&gt;<br \/>\n&lt;artifactId&gt;postgresql&lt;\/artifactId&gt;<br \/>\n&lt;\/dependency&gt; &#8211;&gt;<\/p>\n<p>&lt;!&#8211; H2 Database for In-Memory Testing (optional) &#8211;&gt;<br \/>\n&lt;dependency&gt;<br \/>\n&lt;groupId&gt;com.h2database&lt;\/groupId&gt;<br \/>\n&lt;artifactId&gt;h2&lt;\/artifactId&gt;<br \/>\n&lt;scope&gt;test&lt;\/scope&gt;<br \/>\n&lt;\/dependency&gt;<\/p>\n<p>&lt;!&#8211; Spring Boot Starter Test (for unit testing) &#8211;&gt;<br \/>\n&lt;dependency&gt;<br \/>\n&lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;<br \/>\n&lt;artifactId&gt;spring-boot-starter-test&lt;\/artifactId&gt;<br \/>\n&lt;scope&gt;test&lt;\/scope&gt;<br \/>\n&lt;\/dependency&gt;<\/p>\n<p>&lt;\/dependencies&gt;<br \/>\nThese dependencies will allow Spring Boot to work with H2 (an in-memory database) and<br \/>\nMySQL.<\/p>\n<p><strong>Step 2: Configure Database Properties<\/strong><br \/>\nIn application.yml (or application.properties), configure both data sources. You\u2019ll<br \/>\ndefine connection properties for each database.<br \/>\n# Primary Data Source Configuration<br \/>\nspring.datasource.primary.url=jdbc:mysql:\/\/localhost:3306\/primary_db<br \/>\nspring.datasource.primary.username=root<br \/>\nspring.datasource.primary.password=root_password<br \/>\nspring.datasource.primary.driver-class-name=com.mysql.cj.jdbc.Driver<\/p>\n<p># Secondary Data Source Configuration<br \/>\nspring.datasource.secondary.url=jdbc:mysql:\/\/localhost:3306\/secondary_db<br \/>\nspring.datasource.secondary.username=root<br \/>\nspring.datasource.secondary.password=root_password<br \/>\nspring.datasource.secondary.driver-class-name=com.mysql.cj.jdbc.Driver<\/p>\n<p>Here, we&#8217;ve defined db1 for H2 and db2 for MySQL. Each has its own URL, credentials, and<br \/>\nHibernate dialect.<\/p>\n<p>Step 2: Create Configuration for Each Data Source<br \/>\nFor each data source, you need to define a configuration class. This will handle creating the DataSource, EntityManagerFactory, and TransactionManager beans for each<br \/>\ndatabase.<br \/>\nExample Configuration for the Primary Database:<br \/>\n@Configuration<br \/>\n@EnableTransactionManagement<br \/>\n@EnableJpaRepositories(<br \/>\nbasePackages = &#8220;com.example.repository.primary&#8221;,<br \/>\nentityManagerFactoryRef = &#8220;primaryEntityManagerFactory&#8221;,<br \/>\ntransactionManagerRef = &#8220;primaryTransactionManager&#8221;<\/p>\n<p>)<br \/>\npublic class PrimaryDatabaseConfig {<br \/>\n@Primary<br \/>\n@Bean(name = &#8220;primaryDataSource&#8221;)<br \/>\n@ConfigurationProperties(prefix = &#8220;spring.datasource.primary&#8221;)<br \/>\npublic DataSource primaryDataSource() {<br \/>\nreturn DataSourceBuilder.create().build();<br \/>\n}<br \/>\n@Primary<br \/>\n@Bean(name = &#8220;primaryEntityManagerFactory&#8221;)<br \/>\npublic LocalContainerEntityManagerFactoryBean primaryEntityManagerFactory(<br \/>\nEntityManagerFactoryBuilder builder,<br \/>\n@Qualifier(&#8220;primaryDataSource&#8221;) DataSource dataSource) {<br \/>\nreturn builder<br \/>\n.dataSource(dataSource)<br \/>\n.packages(&#8220;com.example.model.primary&#8221;)<br \/>\n.persistenceUnit(&#8220;primary&#8221;)<br \/>\n.build();<br \/>\n}<br \/>\n@Primary<br \/>\n@Bean(name = &#8220;primaryTransactionManager&#8221;)<\/p>\n<p>public PlatformTransactionManager primaryTransactionManager(<br \/>\n@Qualifier(&#8220;primaryEntityManagerFactory&#8221;) EntityManagerFactory<br \/>\nprimaryEntityManagerFactory) {<br \/>\nreturn new JpaTransactionManager(primaryEntityManagerFactory);<br \/>\n}<br \/>\n}<br \/>\nExample Configuration for the Secondary Database:<\/p>\n<p>@Configuration<br \/>\n@EnableTransactionManagement<br \/>\n@EnableJpaRepositories(<br \/>\nbasePackages = &#8220;com.example.repository.secondary&#8221;,<br \/>\nentityManagerFactoryRef = &#8220;secondaryEntityManagerFactory&#8221;,<br \/>\ntransactionManagerRef = &#8220;secondaryTransactionManager&#8221;<br \/>\n)<br \/>\npublic class SecondaryDatabaseConfig {<br \/>\n@Bean(name = &#8220;secondaryDataSource&#8221;)<br \/>\n@ConfigurationProperties(prefix = &#8220;spring.datasource.secondary&#8221;)<br \/>\npublic DataSource secondaryDataSource() {<br \/>\nreturn DataSourceBuilder.create().build();<br \/>\n}<\/p>\n<p>@Bean(name = &#8220;secondaryEntityManagerFactory&#8221;)<br \/>\npublic LocalContainerEntityManagerFactoryBean secondaryEntityManagerFactory(<br \/>\nEntityManagerFactoryBuilder builder,<br \/>\n@Qualifier(&#8220;secondaryDataSource&#8221;) DataSource dataSource) {<br \/>\nreturn builder<\/p>\n<p>.dataSource(dataSource)<br \/>\n.packages(&#8220;com.example.model.secondary&#8221;)<br \/>\n.persistenceUnit(&#8220;secondary&#8221;)<br \/>\n.build();<br \/>\n}<\/p>\n<p>@Bean(name = &#8220;secondaryTransactionManager&#8221;)<br \/>\npublic PlatformTransactionManager secondaryTransactionManager(<br \/>\n@Qualifier(&#8220;secondaryEntityManagerFactory&#8221;) EntityManagerFactory<br \/>\nsecondaryEntityManagerFactory) {<br \/>\nreturn new JpaTransactionManager(secondaryEntityManagerFactory);<br \/>\n}<br \/>\n}<br \/>\nIn these configurations:<br \/>\n\u25cf DataSource: We define a DataSource bean for each database.<br \/>\n\u25cf EntityManagerFactory: Specifies the package for the entities related to each database and configures the entity manager.<br \/>\n\u25cf TransactionManager: Handles transactions for each specific data source.<\/p>\n<p><strong>Step 3: Define Entity Classes for Each Database<\/strong><br \/>\nThe entity classes are annotated with @Entity, and they must be placed in the corresponding packages as specified in the configuration (com.example.model.primary and com.example.model.secondary).<\/p>\n<p>Example Entity for the Primary Database:<br \/>\n@Entity<br \/>\n@Table(name = &#8220;primary_table&#8221;)<br \/>\npublic class PrimaryEntity {<br \/>\n@Id<br \/>\n@GeneratedValue(strategy = GenerationType.IDENTITY)<\/p>\n<p>private Long id;<br \/>\nprivate String name;<br \/>\n\/\/ getters and setters<br \/>\n}<br \/>\nExample Entity for the Secondary Database:<br \/>\n@Entity<br \/>\n@Table(name = &#8220;secondary_table&#8221;)<br \/>\npublic class SecondaryEntity {<br \/>\n@Id<br \/>\n@GeneratedValue(strategy = GenerationType.IDENTITY)<br \/>\nprivate Long id;<br \/>\nprivate String description;<br \/>\n\/\/ getters and setters<br \/>\n}<\/p>\n<p><strong>Step 4: Create Repositories for Each Data Source<\/strong><br \/>\nIn Spring Data JPA, repositories are interfaces that extend JpaRepository. You need to create separate repositories for each data source and place them in the appropriate packages.<\/p>\n<p>Example Primary Repository:<br \/>\n@Repository<br \/>\npublic interface PrimaryRepository extends JpaRepository&lt;PrimaryEntity, Long&gt; {<br \/>\n} Example Secondary Repository:<br \/>\n@Repository<br \/>\npublic interface SecondaryRepository extends JpaRepository&lt;SecondaryEntity, Long&gt; {<br \/>\n}<br \/>\nThese repositories are scanned based on the base packages defined in your configuration<br \/>\n(com.example.repository.primary and com.example.repository.secondary).<\/p>\n<p><strong>Step 5: Use Repositories in the Service Layer<\/strong><br \/>\nOnce your repositories are set up, you can inject them into your service layer to interact with the respective databases.<br \/>\n@Service<br \/>\npublic class MyService {<br \/>\n@Autowired<br \/>\nprivate PrimaryRepository primaryRepository;<br \/>\n@Autowired<br \/>\nprivate SecondaryRepository secondaryRepository;<\/p>\n<p>public void saveToPrimaryDb(PrimaryEntity primaryEntity) {<br \/>\nprimaryRepository.save(primaryEntity);<br \/>\n} public void saveToSecondaryDb(SecondaryEntity secondaryEntity) {<br \/>\nsecondaryRepository.save(secondaryEntity);<br \/>\n}<br \/>\n}<\/p>\n<p><strong>Step 6: Run and Test<\/strong><br \/>\nAt this point, your application is ready to interact with multiple databases. You can create services that save, update, or query data from both the primary and secondary databases.<\/p>\n<p><strong>Pros:<\/strong><br \/>\n<strong>1. Separation of Concerns<\/strong>: Enables clear separation of different data types or modules, which can improve organizational structure and data management.<\/p>\n<p><strong>2. Legacy Integration:<\/strong> Facilitates integration with existing legacy systems by connecting to different databases without requiring a complete overhaul.<\/p>\n<p><strong>3. Scalability:<\/strong> Allows for scaling parts of your application independently by distributing data across multiple databases.<\/p>\n<p><strong>4. Improved Data Management<\/strong>: Different databases can be optimized for specific use cases, improving performance for particular data operations.<\/p>\n<p><strong>5. Enhanced Security:<\/strong> Sensitive data can be stored in separate databases with stricter access controls, reducing the risk of unauthorized access.<\/p>\n<p><strong>6. Backup and Recovery:<\/strong> Separate databases allow for more flexible backup and recovery strategies tailored to different types of data.<\/p>\n<p><strong>7. Data Redundancy:<\/strong> Reduces the risk of data loss by maintaining copies of critical information in different databases.<\/p>\n<p><strong>8. Specialized Database Features:<\/strong> Utilizes the unique features of different databases (e.g., NoSQL for document storage, relational databases for structured data).<\/p>\n<p><strong>9. Reduced Load on Single Database:<\/strong> Distributes the load, potentially improving performance by avoiding bottlenecks in a single database.<\/p>\n<p style=\"text-align: justify;\"><strong>10. Flexibility in Technology Choices:<\/strong> Allows using different database technologies suited to specific needs within the same application.<\/p>\n<p><strong>Cons:<\/strong><br \/>\n<strong>1. Increased Complexity<\/strong>: More configurations to manage can complicate your codebase.<br \/>\n<strong>2. Performance Overhead:<\/strong> Extra database connections and management may impact performance.<br \/>\n<strong>3. Transaction Management Challenges:<\/strong> Coordinating transactions across multiple databases is complex.<br \/>\n<strong>4. Testing Complexity:<\/strong> More complex test environments are required.<br \/>\n<strong>5. Deployment Overhead<\/strong>: Increased operational burden for deployment and maintenance.<br \/>\n<strong>6. Consistency Issues:<\/strong> Keeping data synchronized across databases can be difficult.<br \/>\n<strong>7. Complex Configuration:<\/strong> Configuration errors can lead to runtime issues.<br \/>\n<strong>8. Resource Consumption:<\/strong> More database connections consume additional system<br \/>\nresources.<br \/>\n<strong>9. Dependency Management:<\/strong> Changes in one database may impact others.<br \/>\n<strong>10. Learning Curve:<\/strong> Higher complexity adds to the learning curve for developers.<\/p>\n<p style=\"text-align: justify;\"><strong>Conclusion<\/strong><br \/>\nUsing multiple databases in a monolithic Spring Boot application with JPA is a powerful approach that can help you handle different data sources while maintaining clean architecture. By configuring multiple DataSource, EntityManagerFactory, and TransactionManager beans, you can manage several databases seamlessly in your application. This approach, while simple, is scalable and can be easily extended if more databases are required in the future.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In a typical monolithic architecture, applications often interact with a single database. However, there are scenarios where you might need to integrate multiple databases, such as when handling legacy systems or optimizing for performance. With Spring Boot, this is not only possible but can be managed efficiently using DataSource, EntityManager, and TransactionManager. In this blog, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":8311,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[990,972,1035,970,966,441],"tags":[998,980,243,279,851],"class_list":["post-8307","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-backend","category-software-architecture","category-software-delivery","category-software-development-methodologies","category-software-engineering","category-spring-boot","tag-backend","tag-software-architecture","tag-spring","tag-spring-boot","tag-springboot"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Managing Multiple Databases in a Monolithic Spring Boot App Using JPA: A Beginner\u2019s Guide - InnovationM - Blog<\/title>\n<meta name=\"description\" content=\"Learn how to efficiently manage multiple databases in a monolithic Spring Boot application using JPA. This beginner&#039;s guide walks you through the step-by-step configuration and implementation, covering DataSource, EntityManager, and TransactionManager setup for seamless integration.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.innovationm.com\/blog\/managing-multiple-databases-in-a-monolithic-spring-boot-app-using-jpa-a-beginners-guide\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Managing Multiple Databases in a Monolithic Spring Boot App Using JPA: A Beginner\u2019s Guide - InnovationM - Blog\" \/>\n<meta property=\"og:description\" content=\"Learn how to efficiently manage multiple databases in a monolithic Spring Boot application using JPA. This beginner&#039;s guide walks you through the step-by-step configuration and implementation, covering DataSource, EntityManager, and TransactionManager setup for seamless integration.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.innovationm.com\/blog\/managing-multiple-databases-in-a-monolithic-spring-boot-app-using-jpa-a-beginners-guide\/\" \/>\n<meta property=\"og:site_name\" content=\"InnovationM - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2024-09-26T17:02:40+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-09-26T17:05:45+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2024\/09\/Managing-Multiple-Databases-in-a-Monolithic-Spring-Boot-App-Using-JPA-1-1024x576.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1024\" \/>\n\t<meta property=\"og:image:height\" content=\"576\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"InnovationM Admin\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"InnovationM Admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/managing-multiple-databases-in-a-monolithic-spring-boot-app-using-jpa-a-beginners-guide\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/managing-multiple-databases-in-a-monolithic-spring-boot-app-using-jpa-a-beginners-guide\\\/\"},\"author\":{\"name\":\"InnovationM Admin\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#\\\/schema\\\/person\\\/a831bf4602d69d1fa452e3de0c8862ed\"},\"headline\":\"Managing Multiple Databases in a Monolithic Spring Boot App Using JPA: A Beginner\u2019s Guide\",\"datePublished\":\"2024-09-26T17:02:40+00:00\",\"dateModified\":\"2024-09-26T17:05:45+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/managing-multiple-databases-in-a-monolithic-spring-boot-app-using-jpa-a-beginners-guide\\\/\"},\"wordCount\":1315,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/managing-multiple-databases-in-a-monolithic-spring-boot-app-using-jpa-a-beginners-guide\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/wp-content\\\/uploads\\\/2024\\\/09\\\/Managing-Multiple-Databases-in-a-Monolithic-Spring-Boot-App-Using-JPA-1.png\",\"keywords\":[\"Backend\",\"Software Architecture\",\"Spring\",\"Spring Boot\",\"springboot\"],\"articleSection\":[\"Backend\",\"Software Architecture\",\"Software Delivery\",\"Software Development Methodologies\",\"Software Engineering\",\"Spring Boot\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/managing-multiple-databases-in-a-monolithic-spring-boot-app-using-jpa-a-beginners-guide\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/managing-multiple-databases-in-a-monolithic-spring-boot-app-using-jpa-a-beginners-guide\\\/\",\"url\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/managing-multiple-databases-in-a-monolithic-spring-boot-app-using-jpa-a-beginners-guide\\\/\",\"name\":\"Managing Multiple Databases in a Monolithic Spring Boot App Using JPA: A Beginner\u2019s Guide - InnovationM - Blog\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/managing-multiple-databases-in-a-monolithic-spring-boot-app-using-jpa-a-beginners-guide\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/managing-multiple-databases-in-a-monolithic-spring-boot-app-using-jpa-a-beginners-guide\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/wp-content\\\/uploads\\\/2024\\\/09\\\/Managing-Multiple-Databases-in-a-Monolithic-Spring-Boot-App-Using-JPA-1.png\",\"datePublished\":\"2024-09-26T17:02:40+00:00\",\"dateModified\":\"2024-09-26T17:05:45+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#\\\/schema\\\/person\\\/a831bf4602d69d1fa452e3de0c8862ed\"},\"description\":\"Learn how to efficiently manage multiple databases in a monolithic Spring Boot application using JPA. This beginner's guide walks you through the step-by-step configuration and implementation, covering DataSource, EntityManager, and TransactionManager setup for seamless integration.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/managing-multiple-databases-in-a-monolithic-spring-boot-app-using-jpa-a-beginners-guide\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/managing-multiple-databases-in-a-monolithic-spring-boot-app-using-jpa-a-beginners-guide\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/managing-multiple-databases-in-a-monolithic-spring-boot-app-using-jpa-a-beginners-guide\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/wp-content\\\/uploads\\\/2024\\\/09\\\/Managing-Multiple-Databases-in-a-Monolithic-Spring-Boot-App-Using-JPA-1.png\",\"contentUrl\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/wp-content\\\/uploads\\\/2024\\\/09\\\/Managing-Multiple-Databases-in-a-Monolithic-Spring-Boot-App-Using-JPA-1.png\",\"width\":2240,\"height\":1260,\"caption\":\"Managing Multiple Databases in a Monolithic Spring Boot App Using JPA: A Beginner\u2019s Guide\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/managing-multiple-databases-in-a-monolithic-spring-boot-app-using-jpa-a-beginners-guide\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Managing Multiple Databases in a Monolithic Spring Boot App Using JPA: A Beginner\u2019s Guide\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/\",\"name\":\"InnovationM - Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#\\\/schema\\\/person\\\/a831bf4602d69d1fa452e3de0c8862ed\",\"name\":\"InnovationM Admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g\",\"caption\":\"InnovationM Admin\"},\"sameAs\":[\"http:\\\/\\\/www.innovationm.com\\\/\"],\"url\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/author\\\/innovationmadmin\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Managing Multiple Databases in a Monolithic Spring Boot App Using JPA: A Beginner\u2019s Guide - InnovationM - Blog","description":"Learn how to efficiently manage multiple databases in a monolithic Spring Boot application using JPA. This beginner's guide walks you through the step-by-step configuration and implementation, covering DataSource, EntityManager, and TransactionManager setup for seamless integration.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.innovationm.com\/blog\/managing-multiple-databases-in-a-monolithic-spring-boot-app-using-jpa-a-beginners-guide\/","og_locale":"en_US","og_type":"article","og_title":"Managing Multiple Databases in a Monolithic Spring Boot App Using JPA: A Beginner\u2019s Guide - InnovationM - Blog","og_description":"Learn how to efficiently manage multiple databases in a monolithic Spring Boot application using JPA. This beginner's guide walks you through the step-by-step configuration and implementation, covering DataSource, EntityManager, and TransactionManager setup for seamless integration.","og_url":"https:\/\/www.innovationm.com\/blog\/managing-multiple-databases-in-a-monolithic-spring-boot-app-using-jpa-a-beginners-guide\/","og_site_name":"InnovationM - Blog","article_published_time":"2024-09-26T17:02:40+00:00","article_modified_time":"2024-09-26T17:05:45+00:00","og_image":[{"width":1024,"height":576,"url":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2024\/09\/Managing-Multiple-Databases-in-a-Monolithic-Spring-Boot-App-Using-JPA-1-1024x576.png","type":"image\/png"}],"author":"InnovationM Admin","twitter_misc":{"Written by":"InnovationM Admin","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.innovationm.com\/blog\/managing-multiple-databases-in-a-monolithic-spring-boot-app-using-jpa-a-beginners-guide\/#article","isPartOf":{"@id":"https:\/\/www.innovationm.com\/blog\/managing-multiple-databases-in-a-monolithic-spring-boot-app-using-jpa-a-beginners-guide\/"},"author":{"name":"InnovationM Admin","@id":"https:\/\/www.innovationm.com\/blog\/#\/schema\/person\/a831bf4602d69d1fa452e3de0c8862ed"},"headline":"Managing Multiple Databases in a Monolithic Spring Boot App Using JPA: A Beginner\u2019s Guide","datePublished":"2024-09-26T17:02:40+00:00","dateModified":"2024-09-26T17:05:45+00:00","mainEntityOfPage":{"@id":"https:\/\/www.innovationm.com\/blog\/managing-multiple-databases-in-a-monolithic-spring-boot-app-using-jpa-a-beginners-guide\/"},"wordCount":1315,"commentCount":0,"image":{"@id":"https:\/\/www.innovationm.com\/blog\/managing-multiple-databases-in-a-monolithic-spring-boot-app-using-jpa-a-beginners-guide\/#primaryimage"},"thumbnailUrl":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2024\/09\/Managing-Multiple-Databases-in-a-Monolithic-Spring-Boot-App-Using-JPA-1.png","keywords":["Backend","Software Architecture","Spring","Spring Boot","springboot"],"articleSection":["Backend","Software Architecture","Software Delivery","Software Development Methodologies","Software Engineering","Spring Boot"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.innovationm.com\/blog\/managing-multiple-databases-in-a-monolithic-spring-boot-app-using-jpa-a-beginners-guide\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.innovationm.com\/blog\/managing-multiple-databases-in-a-monolithic-spring-boot-app-using-jpa-a-beginners-guide\/","url":"https:\/\/www.innovationm.com\/blog\/managing-multiple-databases-in-a-monolithic-spring-boot-app-using-jpa-a-beginners-guide\/","name":"Managing Multiple Databases in a Monolithic Spring Boot App Using JPA: A Beginner\u2019s Guide - InnovationM - Blog","isPartOf":{"@id":"https:\/\/www.innovationm.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.innovationm.com\/blog\/managing-multiple-databases-in-a-monolithic-spring-boot-app-using-jpa-a-beginners-guide\/#primaryimage"},"image":{"@id":"https:\/\/www.innovationm.com\/blog\/managing-multiple-databases-in-a-monolithic-spring-boot-app-using-jpa-a-beginners-guide\/#primaryimage"},"thumbnailUrl":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2024\/09\/Managing-Multiple-Databases-in-a-Monolithic-Spring-Boot-App-Using-JPA-1.png","datePublished":"2024-09-26T17:02:40+00:00","dateModified":"2024-09-26T17:05:45+00:00","author":{"@id":"https:\/\/www.innovationm.com\/blog\/#\/schema\/person\/a831bf4602d69d1fa452e3de0c8862ed"},"description":"Learn how to efficiently manage multiple databases in a monolithic Spring Boot application using JPA. This beginner's guide walks you through the step-by-step configuration and implementation, covering DataSource, EntityManager, and TransactionManager setup for seamless integration.","breadcrumb":{"@id":"https:\/\/www.innovationm.com\/blog\/managing-multiple-databases-in-a-monolithic-spring-boot-app-using-jpa-a-beginners-guide\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.innovationm.com\/blog\/managing-multiple-databases-in-a-monolithic-spring-boot-app-using-jpa-a-beginners-guide\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.innovationm.com\/blog\/managing-multiple-databases-in-a-monolithic-spring-boot-app-using-jpa-a-beginners-guide\/#primaryimage","url":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2024\/09\/Managing-Multiple-Databases-in-a-Monolithic-Spring-Boot-App-Using-JPA-1.png","contentUrl":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2024\/09\/Managing-Multiple-Databases-in-a-Monolithic-Spring-Boot-App-Using-JPA-1.png","width":2240,"height":1260,"caption":"Managing Multiple Databases in a Monolithic Spring Boot App Using JPA: A Beginner\u2019s Guide"},{"@type":"BreadcrumbList","@id":"https:\/\/www.innovationm.com\/blog\/managing-multiple-databases-in-a-monolithic-spring-boot-app-using-jpa-a-beginners-guide\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.innovationm.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Managing Multiple Databases in a Monolithic Spring Boot App Using JPA: A Beginner\u2019s Guide"}]},{"@type":"WebSite","@id":"https:\/\/www.innovationm.com\/blog\/#website","url":"https:\/\/www.innovationm.com\/blog\/","name":"InnovationM - Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.innovationm.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.innovationm.com\/blog\/#\/schema\/person\/a831bf4602d69d1fa452e3de0c8862ed","name":"InnovationM Admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g","caption":"InnovationM Admin"},"sameAs":["http:\/\/www.innovationm.com\/"],"url":"https:\/\/www.innovationm.com\/blog\/author\/innovationmadmin\/"}]}},"_links":{"self":[{"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/posts\/8307","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/comments?post=8307"}],"version-history":[{"count":0,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/posts\/8307\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/media\/8311"}],"wp:attachment":[{"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/media?parent=8307"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/categories?post=8307"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/tags?post=8307"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}