Doing a join over 2 tables in different databases using Hibernate

后端 未结 2 1455
再見小時候
再見小時候 2020-12-09 05:07

I have two tables in two separate Oracle databases (not schemas) that I need to join in Hibernate. Currently, I have two Hibernate session

2条回答
  •  被撕碎了的回忆
    2020-12-09 05:45

    You have a couple of problems unfortunately.

    • Hibernate does not supporting joining across multiple "physical" database instances
    • Out of the box, most database don't support joining across multiple "physical" database instances

    Fundamentally DBs are only good/performant at joining tables that are in the same database. There are ways of joining across databases but if the size of both tables is big this can be a problem, and peformance may suffer. Do some googling on "oracle join across database" and you'll find some pointers on how to do this but it involves fiddling around with Oracle create a virtual link from one DB to the other.

    I would consider either doing the join in memory, if you are comfortable the data set will fit within the memory constraints AND you are only doing this in one special case.

    If you'll need to do different joins between these two databases then I would go for a more permanent solution, like the Oracle linking above.

提交回复
热议问题