Add multi-datasource module: two databases with per-database DataSource, Flyway, EntityManagerFactory and transaction manager on Boot 4.1
Working setup plus one small application per way of getting it wrong (no @Primary, @Primary only, url vs jdbc-url, wrong repository package, Flyway auto-configuration), plain vs named @Transactional, and ChainedTransactionManager with a failing commit. Transcripts are written by the tests. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Uu7q8vPeREyT4218EJPzz1
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
# Two databases, each with its own DataSource, Flyway, EntityManagerFactory and transaction manager
|
||||
|
||||
|
||||
--- the two DataSources (one pool each, configured separately) ---
|
||||
customersDataSource pool=customers-pool max=4 url=jdbc:h2:mem:customers primary=true
|
||||
ordersDataSource pool=orders-pool max=8 url=jdbc:h2:mem:orders primary=false
|
||||
|
||||
--- Flyway ran once per database, each with its own history ---
|
||||
customers flyway_schema_history: [1 customer]
|
||||
orders flyway_schema_history: [1 purchase order, 2 index customer]
|
||||
|
||||
--- what each EntityManagerFactory manages ---
|
||||
EntityManagerFactory beans: [customersEntityManagerFactory, ordersEntityManagerFactory]
|
||||
customersEntityManagerFactory entities=[Customer]
|
||||
ordersEntityManagerFactory entities=[PurchaseOrder]
|
||||
|
||||
--- transaction managers ---
|
||||
beans: [customersTransactionManager, ordersTransactionManager]
|
||||
customersTransactionManager primary=true
|
||||
ordersTransactionManager primary=false
|
||||
|
||||
--- save one customer and one order through the two repositories ---
|
||||
customers database tables: [CUSTOMER, flyway_schema_history]
|
||||
orders database tables: [PURCHASE_ORDER, flyway_schema_history]
|
||||
rows: customers.customer=1 orders.purchase_order=1
|
||||
Reference in New Issue
Block a user