How to establish one to many mapping from two postgres DB - postgresql

I have a created different tables in two different PostgreSQL DB now i want to establish one to many and one to one relationship between two different DB's table How i can do this using hibernate?

To achive your goal you have to create a DB Link between the two DBs because you only can use realtionship mapping with hibernate with one DB connection.
Please read more about DB link here:
https://www.postgresql.org/docs/current/dblink.html

Related

Spring Data Sources: Can I have 2 data sources that point to a read/write endpoint and a read only endpoint but both data sources use the same entitys

I have the need of creating 2 data sources in spring, one pointed to a read replica and one to a primary db. Both the db's are the same since the replica is just a copy of the primary. Therefore, they both use the same exact entities. Since I've created 2 data sources, I can no longer use the #EntityScan annotation. Before, when using the #EntityScan on my singular data source my connections to the database worked great. When I define two data sources and custom entity managers for each I can still connect to the databases just fine, but all my SQL queries will fail. It's as if the schemas are now incorrect and I'll get errors like columns don't exist when I know they do. Are there resources on how to achieve this design? I have been trying to follow this example:
https://www.baeldung.com/spring-boot-configure-multiple-datasources

How to replicate rows into different tables of different database in postgresql?

I use postgresql. I have many databases in a server. There is one database which I use the most say 'main'. This 'main' has many tables inside it. And also other databases have many tables inside them.
What I want to do is, whenever a new row is inserted into 'main.users' table I wish to insert the same data into 'users' table of other databases. How shall I do it in postgresql? Similarly I wish to do the same for all actions like UPDATE, DELETE etc.,
I had gone through the "logical replication" concept as suggested by you. In my case I know the source db name up front and I will come to know the target db name as part of the query. So it is going to be dynamic.
How to achieve this? is there any db concept available in postgresql? Or I welcome all other possible ways as well. Please share me some idea on this.
If this is all on the same Postgres instance (aka "cluster"), then I would recommend to use a foreign table to access the tables from the "main" database in the other databases.
Those foreign tables look like "local" tables inside each database, but access the original data in the source database directly, so there is no need to synchronize anything.
Upgrade to a recent PostgreSQL release and use logical replication.
Add a trigger on the table in the master database that uses dblink to access and write the other databases.
Be sure to consider what should be done if the row alreasdy exists remotely, or if the rome server is unreachable.
Also not that updates propogated usign dblink are not rolled back if the inboking transaction is rolled back

PostgreSQL data warehouse: create separate databases or different tables within the same database?

We seek to run cross-table queries and perform different type of merges. For cross-database queries we need to establish connection every time.
So to answer your question,
we should create multiple(different)tables within same database.
because cross database operation is not supported(for ex. In short you can't do the join on 2 tables in different database)
But if you want to segregate your data within same database you can create different schemas/layer .and create your tables under that.
for ex.
**1st load landingLayer.tablename
2nd transformation goodDataLayer.tablename
3rd transformation widgetLayer.tablename**

How to refer two schemas in single entity using ejb

I want to use two different schema in database, each schema has same set of Tables but data differs. How to use same entity two point different schemas in ejb.
Thanks in advance

What is the difference between multiple data sources and multi tenancy?

In context of mongodb and gorm, If we need to have different databases for different clients, then are multi-tenancy (With Database mode) and multiple data source approach are 2 solutions to achieve the same thing or is there any difference between them?
Multiple Data Source Solution:
http://gorm.grails.org/latest/mongodb/manual/#multipleDataSources
Multiple Tenant Solution:
http://gorm.grails.org/latest/mongodb/manual/#multiTenancy
Well they are not meant to achieve the same purpose
tldr;
Multiple Data Source is meant to have different databases (collections if you only plan to use mongodb) for different objects while Multi Tenant will store the same object but add a discriminator to identify client specific data.
If your question is about supporting different databases for different clients the answer will be to go with multi tenant
Multiple Data Sources
Grails supports (for long) to have multiple database for the same application (it can be different db vendor or different db from same vendor). The purpose is to have specific data stored in a different db/namespace.
For example, you can decide to have a db for all core entity of your business and to have a dedicated db for all audit/logging things. When using multiple data sources you will map an object to a dedicated datasource
Multi Tenancy (with database tenant as per OP context)
In mutli tenancy (database tenant) on the other hand, grails will have a single database schema for your client to store all the objects. so data from Client A will be in another db than Client B. Grails will have some default tenant resolver (that you can still override if needed) which will manage to determine which database needs to be queried depending the context.