I’ve two database connections as follows:
val db1 = Database.connect(
"jdbc:postgresql://localhost:5432/db1",
driver = ".postgresql.Driver",
user = "postgres",
password = "password")
val db2 = Database.connect(
"jdbc:postgresql://localhost:5432/db2",
driver = ".postgresql.Driver",
user = "postgres",
password = "password"
)
Now if I run the transactions as follows, this does not work as db1 is not being connected.
transaction(db1){
….
}
Instead, if I switch the order in which the above database connections are declared, then it will work.
val db2 = Database.connect(
"jdbc:postgresql://localhost:5432/db2",
driver = ".postgresql.Driver",
user = "postgres",
password = "password")
val db1 = Database.connect(
"jdbc:postgresql://localhost:5432/db1",
driver = ".postgresql.Driver",
user = "postgres",
password = "password"
)
transaction(db1){
….
}
Why is it so? My understanding from the exposed documentation is that every time we call the transaction with the database connection object parameter (i.e., db1) the connection gets established. the document even says we can nest different transactions under other transactions. What am I missing in my understanding? Or, is that a matter of some settings/configuration? Can someone please help me? Thanks in advance
One thing you may need to observe here is both connections are to the same Postgres server on the same machine but towards different databases.