{"id":25068,"date":"2024-03-16T04:18:15","date_gmt":"2024-03-16T04:18:15","guid":{"rendered":"https:\/\/www.silicloud.com\/blog\/how-to-implement-dynamic-switching-of-data-sources-in-jpa\/"},"modified":"2024-03-22T05:16:45","modified_gmt":"2024-03-22T05:16:45","slug":"how-to-implement-dynamic-switching-of-data-sources-in-jpa","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/blog\/how-to-implement-dynamic-switching-of-data-sources-in-jpa\/","title":{"rendered":"How to implement dynamic switching of data sources in JPA?"},"content":{"rendered":"<p>One way to achieve dynamic switching of data sources in JPA is by using multiple EntityManagerFactory instances.<\/p>\n<ol>\n<li>Configure connection information for multiple data sources: Define connection information for multiple data sources in the configuration file, such as database URL, username, password, etc. You can use either application.properties or application.yml file for configuration.<\/li>\n<li>Create multiple EntityManagerFactories: Multiple EntityManagerFactories can be created based on the data source connection information defined in the configuration file. EntityManagerFactories can be created as beans using the @Configuration annotation, specifying the corresponding data source connection information.<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><span class=\"hljs-meta\">@Configuration<\/span>\r\n<span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title class_\">DataSourceConfig<\/span> {\r\n    \r\n    <span class=\"hljs-meta\">@Bean<\/span>\r\n    <span class=\"hljs-keyword\">public<\/span> DataSource <span class=\"hljs-title function_\">dataSource1<\/span><span class=\"hljs-params\">()<\/span> {\r\n        <span class=\"hljs-comment\">\/\/ \u6570\u636e\u6e901\u7684\u8fde\u63a5\u4fe1\u606f<\/span>\r\n        <span class=\"hljs-comment\">\/\/ ...<\/span>\r\n    }\r\n\r\n    <span class=\"hljs-meta\">@Bean<\/span>\r\n    <span class=\"hljs-keyword\">public<\/span> DataSource <span class=\"hljs-title function_\">dataSource2<\/span><span class=\"hljs-params\">()<\/span> {\r\n        <span class=\"hljs-comment\">\/\/ \u6570\u636e\u6e902\u7684\u8fde\u63a5\u4fe1\u606f<\/span>\r\n        <span class=\"hljs-comment\">\/\/ ...<\/span>\r\n    }\r\n\r\n    <span class=\"hljs-meta\">@Bean<\/span>\r\n    <span class=\"hljs-meta\">@Primary<\/span>\r\n    <span class=\"hljs-keyword\">public<\/span> EntityManagerFactory <span class=\"hljs-title function_\">entityManagerFactory1<\/span><span class=\"hljs-params\">()<\/span> {\r\n        <span class=\"hljs-type\">LocalContainerEntityManagerFactoryBean<\/span> <span class=\"hljs-variable\">factory<\/span> <span class=\"hljs-operator\">=<\/span> <span class=\"hljs-keyword\">new<\/span> <span class=\"hljs-title class_\">LocalContainerEntityManagerFactoryBean<\/span>();\r\n        factory.setDataSource(dataSource1());\r\n        <span class=\"hljs-comment\">\/\/ \u8bbe\u7f6e\u5176\u4ed6\u914d\u7f6e\u4fe1\u606f<\/span>\r\n        <span class=\"hljs-comment\">\/\/ ...<\/span>\r\n        factory.afterPropertiesSet();\r\n        <span class=\"hljs-keyword\">return<\/span> factory.getObject();\r\n    }\r\n\r\n    <span class=\"hljs-meta\">@Bean<\/span>\r\n    <span class=\"hljs-keyword\">public<\/span> EntityManagerFactory <span class=\"hljs-title function_\">entityManagerFactory2<\/span><span class=\"hljs-params\">()<\/span> {\r\n        <span class=\"hljs-type\">LocalContainerEntityManagerFactoryBean<\/span> <span class=\"hljs-variable\">factory<\/span> <span class=\"hljs-operator\">=<\/span> <span class=\"hljs-keyword\">new<\/span> <span class=\"hljs-title class_\">LocalContainerEntityManagerFactoryBean<\/span>();\r\n        factory.setDataSource(dataSource2());\r\n        <span class=\"hljs-comment\">\/\/ \u8bbe\u7f6e\u5176\u4ed6\u914d\u7f6e\u4fe1\u606f<\/span>\r\n        <span class=\"hljs-comment\">\/\/ ...<\/span>\r\n        factory.afterPropertiesSet();\r\n        <span class=\"hljs-keyword\">return<\/span> factory.getObject();\r\n    }\r\n}\r\n<\/code><\/pre>\n<ol>\n<li>A DataSource that dynamically routes connections to multiple databases based on a certain criteria.<\/li>\n<li>AbstractRoutingDataSource is a class in Java that allows for dynamic switching of data sources at runtime.<\/li>\n<li>Find the current lookup key.<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><span class=\"hljs-keyword\">import<\/span> org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;\r\n\r\n<span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title class_\">DynamicDataSource<\/span> <span class=\"hljs-keyword\">extends<\/span> <span class=\"hljs-title class_\">AbstractRoutingDataSource<\/span> {\r\n\r\n    <span class=\"hljs-meta\">@Override<\/span>\r\n    <span class=\"hljs-keyword\">protected<\/span> Object <span class=\"hljs-title function_\">determineCurrentLookupKey<\/span><span class=\"hljs-params\">()<\/span> {\r\n        <span class=\"hljs-comment\">\/\/ \u6839\u636e\u81ea\u5b9a\u4e49\u7684\u89c4\u5219\u6765\u8fd4\u56de\u5f53\u524d\u8981\u4f7f\u7528\u7684\u6570\u636e\u6e90\u7684\u540d\u79f0<\/span>\r\n        <span class=\"hljs-comment\">\/\/ ...<\/span>\r\n    }\r\n}\r\n<\/code><\/pre>\n<ol>\n<li>Configure dynamic data source: Configure dynamic data source in the configuration file, and associate multiple EntityManagerFactory with the dynamic data source.<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><span class=\"hljs-meta\">@Configuration<\/span>\r\n<span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title class_\">DataSourceConfig<\/span> {\r\n    \r\n    <span class=\"hljs-comment\">\/\/ ...<\/span>\r\n\r\n    <span class=\"hljs-meta\">@Bean<\/span>\r\n    <span class=\"hljs-keyword\">public<\/span> DataSource <span class=\"hljs-title function_\">dynamicDataSource<\/span><span class=\"hljs-params\">()<\/span> {\r\n        <span class=\"hljs-type\">DynamicDataSource<\/span> <span class=\"hljs-variable\">dataSource<\/span> <span class=\"hljs-operator\">=<\/span> <span class=\"hljs-keyword\">new<\/span> <span class=\"hljs-title class_\">DynamicDataSource<\/span>();\r\n        dataSource.setDefaultTargetDataSource(entityManagerFactory1().createEntityManager().getEntityManagerFactory().getDataSource());\r\n        Map&lt;Object, Object&gt; targetDataSources = <span class=\"hljs-keyword\">new<\/span> <span class=\"hljs-title class_\">HashMap<\/span>&lt;&gt;();\r\n        targetDataSources.put(<span class=\"hljs-string\">\"dataSource1\"<\/span>, entityManagerFactory1().createEntityManager().getEntityManagerFactory().getDataSource());\r\n        targetDataSources.put(<span class=\"hljs-string\">\"dataSource2\"<\/span>, entityManagerFactory2().createEntityManager().getEntityManagerFactory().getDataSource());\r\n        dataSource.setTargetDataSources(targetDataSources);\r\n        <span class=\"hljs-keyword\">return<\/span> dataSource;\r\n    }\r\n\r\n    <span class=\"hljs-meta\">@Bean<\/span>\r\n    <span class=\"hljs-keyword\">public<\/span> JpaTransactionManager <span class=\"hljs-title function_\">transactionManager<\/span><span class=\"hljs-params\">()<\/span> {\r\n        <span class=\"hljs-type\">JpaTransactionManager<\/span> <span class=\"hljs-variable\">transactionManager<\/span> <span class=\"hljs-operator\">=<\/span> <span class=\"hljs-keyword\">new<\/span> <span class=\"hljs-title class_\">JpaTransactionManager<\/span>();\r\n        transactionManager.setEntityManagerFactory(entityManagerFactory1());\r\n        <span class=\"hljs-keyword\">return<\/span> transactionManager;\r\n    }\r\n}\r\n<\/code><\/pre>\n<ol>\n<li>a special variable that is local to each thread<\/li>\n<li>Find the current lookup key.<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title class_\">DataSourceContextHolder<\/span> {\r\n    <span class=\"hljs-keyword\">private<\/span> <span class=\"hljs-keyword\">static<\/span> <span class=\"hljs-keyword\">final<\/span> ThreadLocal&lt;String&gt; contextHolder = <span class=\"hljs-keyword\">new<\/span> <span class=\"hljs-title class_\">ThreadLocal<\/span>&lt;&gt;();\r\n\r\n    <span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">static<\/span> <span class=\"hljs-keyword\">void<\/span> <span class=\"hljs-title function_\">setDataSource<\/span><span class=\"hljs-params\">(String dataSourceName)<\/span> {\r\n        contextHolder.set(dataSourceName);\r\n    }\r\n\r\n    <span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">static<\/span> String <span class=\"hljs-title function_\">getDataSource<\/span><span class=\"hljs-params\">()<\/span> {\r\n        <span class=\"hljs-keyword\">return<\/span> contextHolder.get();\r\n    }\r\n\r\n    <span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">static<\/span> <span class=\"hljs-keyword\">void<\/span> <span class=\"hljs-title function_\">clearDataSource<\/span><span class=\"hljs-params\">()<\/span> {\r\n        contextHolder.remove();\r\n    }\r\n}\r\n\r\n<span class=\"hljs-comment\">\/\/ \u4f7f\u7528\u52a8\u6001\u6570\u636e\u6e90<\/span>\r\n<span class=\"hljs-meta\">@Service<\/span>\r\n<span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title class_\">UserServiceImpl<\/span> <span class=\"hljs-keyword\">implements<\/span> <span class=\"hljs-title class_\">UserService<\/span> {\r\n\r\n    <span class=\"hljs-meta\">@Autowired<\/span>\r\n    <span class=\"hljs-keyword\">private<\/span> UserRepository userRepository;\r\n\r\n    <span class=\"hljs-meta\">@Override<\/span>\r\n    <span class=\"hljs-keyword\">public<\/span> User <span class=\"hljs-title function_\">findById<\/span><span class=\"hljs-params\">(Long id)<\/span> {\r\n        <span class=\"hljs-type\">String<\/span> <span class=\"hljs-variable\">dataSourceName<\/span> <span class=\"hljs-operator\">=<\/span> determineDataSourceName(id);\r\n        DataSourceContextHolder.setDataSource(dataSourceName);\r\n        <span class=\"hljs-type\">User<\/span> <span class=\"hljs-variable\">user<\/span> <span class=\"hljs-operator\">=<\/span> userRepository.findById(id);\r\n        DataSourceContextHolder.clearDataSource();\r\n        <span class=\"hljs-keyword\">return<\/span> user;\r\n    }\r\n\r\n    <span class=\"hljs-keyword\">private<\/span> String <span class=\"hljs-title function_\">determineDataSourceName<\/span><span class=\"hljs-params\">(Long id)<\/span> {\r\n        <span class=\"hljs-comment\">\/\/ \u6839\u636eid\u5224\u65ad\u8981\u4f7f\u7528\u7684\u6570\u636e\u6e90\u7684\u540d\u79f0<\/span>\r\n        <span class=\"hljs-comment\">\/\/ ...<\/span>\r\n    }\r\n}\r\n<\/code><\/pre>\n<p>By following the above steps, you can dynamically switch data sources in JPA. It is important to make sure to promptly clear the data source name in ThreadLocal after each operation to avoid affecting subsequent operations.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>One way to achieve dynamic switching of data sources in JPA is by using multiple EntityManagerFactory instances. Configure connection information for multiple data sources: Define connection information for multiple data sources in the configuration file, such as database URL, username, password, etc. You can use either application.properties or application.yml file for configuration. Create multiple EntityManagerFactories: [&hellip;]<\/p>\n","protected":false},"author":14,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-25068","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.5 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to implement dynamic switching of data sources in JPA? - Blog - Silicon Cloud<\/title>\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.silicloud.com\/blog\/how-to-implement-dynamic-switching-of-data-sources-in-jpa\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to implement dynamic switching of data sources in JPA?\" \/>\n<meta property=\"og:description\" content=\"One way to achieve dynamic switching of data sources in JPA is by using multiple EntityManagerFactory instances. Configure connection information for multiple data sources: Define connection information for multiple data sources in the configuration file, such as database URL, username, password, etc. You can use either application.properties or application.yml file for configuration. Create multiple EntityManagerFactories: [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/blog\/how-to-implement-dynamic-switching-of-data-sources-in-jpa\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/SiliCloudGlobal\/\" \/>\n<meta property=\"article:published_time\" content=\"2024-03-16T04:18:15+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-03-22T05:16:45+00:00\" \/>\n<meta name=\"author\" content=\"Noah Thompson\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@SiliCloudGlobal\" \/>\n<meta name=\"twitter:site\" content=\"@SiliCloudGlobal\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Noah Thompson\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/how-to-implement-dynamic-switching-of-data-sources-in-jpa\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/how-to-implement-dynamic-switching-of-data-sources-in-jpa\/\"},\"author\":{\"name\":\"Noah Thompson\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/2e83cc6ab9f60d36921c2d0f9f280f4a\"},\"headline\":\"How to implement dynamic switching of data sources in JPA?\",\"datePublished\":\"2024-03-16T04:18:15+00:00\",\"dateModified\":\"2024-03-22T05:16:45+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/how-to-implement-dynamic-switching-of-data-sources-in-jpa\/\"},\"wordCount\":207,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\"},\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/how-to-implement-dynamic-switching-of-data-sources-in-jpa\/\",\"url\":\"https:\/\/www.silicloud.com\/blog\/how-to-implement-dynamic-switching-of-data-sources-in-jpa\/\",\"name\":\"How to implement dynamic switching of data sources in JPA? - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#website\"},\"datePublished\":\"2024-03-16T04:18:15+00:00\",\"dateModified\":\"2024-03-22T05:16:45+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/how-to-implement-dynamic-switching-of-data-sources-in-jpa\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/blog\/how-to-implement-dynamic-switching-of-data-sources-in-jpa\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/how-to-implement-dynamic-switching-of-data-sources-in-jpa\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.silicloud.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to implement dynamic switching of data sources in JPA?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#website\",\"url\":\"https:\/\/www.silicloud.com\/blog\/\",\"name\":\"Silicon Cloud Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\",\"name\":\"Silicon Cloud Blog\",\"url\":\"https:\/\/www.silicloud.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png\",\"contentUrl\":\"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png\",\"width\":1024,\"height\":1024,\"caption\":\"Silicon Cloud Blog\"},\"image\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/SiliCloudGlobal\/\",\"https:\/\/twitter.com\/SiliCloudGlobal\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/2e83cc6ab9f60d36921c2d0f9f280f4a\",\"name\":\"Noah Thompson\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/350e537e1530ede2762ee0237e877d6693f4f7163ab4f303202cc9a6b27b6cb4?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/350e537e1530ede2762ee0237e877d6693f4f7163ab4f303202cc9a6b27b6cb4?s=96&d=mm&r=g\",\"caption\":\"Noah Thompson\"},\"url\":\"https:\/\/www.silicloud.com\/blog\/author\/noahthompson\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"How to implement dynamic switching of data sources in JPA? - Blog - Silicon Cloud","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.silicloud.com\/blog\/how-to-implement-dynamic-switching-of-data-sources-in-jpa\/","og_locale":"en_US","og_type":"article","og_title":"How to implement dynamic switching of data sources in JPA?","og_description":"One way to achieve dynamic switching of data sources in JPA is by using multiple EntityManagerFactory instances. Configure connection information for multiple data sources: Define connection information for multiple data sources in the configuration file, such as database URL, username, password, etc. You can use either application.properties or application.yml file for configuration. Create multiple EntityManagerFactories: [&hellip;]","og_url":"https:\/\/www.silicloud.com\/blog\/how-to-implement-dynamic-switching-of-data-sources-in-jpa\/","og_site_name":"Blog - Silicon Cloud","article_publisher":"https:\/\/www.facebook.com\/SiliCloudGlobal\/","article_published_time":"2024-03-16T04:18:15+00:00","article_modified_time":"2024-03-22T05:16:45+00:00","author":"Noah Thompson","twitter_card":"summary_large_image","twitter_creator":"@SiliCloudGlobal","twitter_site":"@SiliCloudGlobal","twitter_misc":{"Written by":"Noah Thompson","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.silicloud.com\/blog\/how-to-implement-dynamic-switching-of-data-sources-in-jpa\/#article","isPartOf":{"@id":"https:\/\/www.silicloud.com\/blog\/how-to-implement-dynamic-switching-of-data-sources-in-jpa\/"},"author":{"name":"Noah Thompson","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/2e83cc6ab9f60d36921c2d0f9f280f4a"},"headline":"How to implement dynamic switching of data sources in JPA?","datePublished":"2024-03-16T04:18:15+00:00","dateModified":"2024-03-22T05:16:45+00:00","mainEntityOfPage":{"@id":"https:\/\/www.silicloud.com\/blog\/how-to-implement-dynamic-switching-of-data-sources-in-jpa\/"},"wordCount":207,"commentCount":0,"publisher":{"@id":"https:\/\/www.silicloud.com\/blog\/#organization"},"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/blog\/how-to-implement-dynamic-switching-of-data-sources-in-jpa\/","url":"https:\/\/www.silicloud.com\/blog\/how-to-implement-dynamic-switching-of-data-sources-in-jpa\/","name":"How to implement dynamic switching of data sources in JPA? - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/blog\/#website"},"datePublished":"2024-03-16T04:18:15+00:00","dateModified":"2024-03-22T05:16:45+00:00","breadcrumb":{"@id":"https:\/\/www.silicloud.com\/blog\/how-to-implement-dynamic-switching-of-data-sources-in-jpa\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/blog\/how-to-implement-dynamic-switching-of-data-sources-in-jpa\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/blog\/how-to-implement-dynamic-switching-of-data-sources-in-jpa\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.silicloud.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to implement dynamic switching of data sources in JPA?"}]},{"@type":"WebSite","@id":"https:\/\/www.silicloud.com\/blog\/#website","url":"https:\/\/www.silicloud.com\/blog\/","name":"Silicon Cloud Blog","description":"","publisher":{"@id":"https:\/\/www.silicloud.com\/blog\/#organization"},"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.silicloud.com\/blog\/#organization","name":"Silicon Cloud Blog","url":"https:\/\/www.silicloud.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png","contentUrl":"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png","width":1024,"height":1024,"caption":"Silicon Cloud Blog"},"image":{"@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/SiliCloudGlobal\/","https:\/\/twitter.com\/SiliCloudGlobal"]},{"@type":"Person","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/2e83cc6ab9f60d36921c2d0f9f280f4a","name":"Noah Thompson","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/350e537e1530ede2762ee0237e877d6693f4f7163ab4f303202cc9a6b27b6cb4?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/350e537e1530ede2762ee0237e877d6693f4f7163ab4f303202cc9a6b27b6cb4?s=96&d=mm&r=g","caption":"Noah Thompson"},"url":"https:\/\/www.silicloud.com\/blog\/author\/noahthompson\/"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts\/25068","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/users\/14"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/comments?post=25068"}],"version-history":[{"count":1,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts\/25068\/revisions"}],"predecessor-version":[{"id":59145,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts\/25068\/revisions\/59145"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/media?parent=25068"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/categories?post=25068"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/tags?post=25068"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}