Accessing multiple database from a Java web application using JPA/EclipseLink/EJB

前端 未结 5 433
猫巷女王i
猫巷女王i 2020-12-29 15:21

I have built a simple SOAP java application(server side) and I am using Glassfish4,JPA/EclipseLink,EJB. I have set the db connections(resources/poo

5条回答
  •  时光说笑
    2020-12-29 16:02

    When dealing with one app and multiple DBs EclipseLink provides two solutions. Which one is better suited for you depends on your use-case, if

    Users need to map expose multiple persistence units as a single persistence context within an application.

    Take a look at Using Multiple Databases with a Composite Persistence Unit

    If your case is that

    Multiple application clients must share data sources, with private access to their data environment.

    than take a look at Tenant Isolation Using EclipseLink

    Alternatively, this blog post describes a way of designing a multi-tenancy, without binding to vendor specific functionality

    UPDATE with respect to the comment

    I don't think that the type of dynamic data source routing that you're after exists as a ready made construct of glassfish. But it should not be too hard to implement it either. You should take a look at the TomEE's dynamic datasource api and the reference implementation they provided. You should be able to write your own router based on it without too much issues

提交回复
热议问题