Changing Persistence Unit dynamically - JPA

前端 未结 4 1277
被撕碎了的回忆
被撕碎了的回忆 2020-11-29 03:26

Persistence units in persistence.xml are created during building the application. As I want to change the database url at runtime, is there any way to modify the persistence

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-29 04:05

    In Long-lived Session Architecture you should create a Plug-in-Framework.

    Therefore you need to create a different Thread-Group and Class-Repository.

    This might be your Class-Loader-Tree

    • System-Class-Loader (usually a URLClassLoader, contains the Entitys)
      • JPA-Class-Loader
        • Load your jpa.jar with persistence.xml inside, specify the Database-Configuration from Application-Class-Loader
        • Instanciate your entityManager/session-factory.
        • Load any plugin you need to work with the DataBase. Execute Unit-Tests (;D) and Plugin-Integration-Tests.

提交回复
热议问题