JPA Hibernate Dynamic entity mapping & persistence at runtime

后端 未结 2 1121
感动是毒
感动是毒 2021-01-19 21:55

Basically we have a spring boot application that requires that the user can define his/her own set of fields and that these fields should be persisted in their own class/tab

2条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-19 22:41

    Hibernate maps entities to tables, and the metadata is built during bootstrap. So, you can't modify it on the fly while the application is running.

    However, as long as you keep on adding new tables without modifying the existing structure, you can address this issue at the architecture level:

    1. You make the class changes you need.
    2. You build the project artifacts.
    3. You deploy the new project artifacts to a new server.
    4. You switch traffic from the old server instance to the new one from the load balancer without any downtime.

    Or, just use a NoSQL database like MongoDB with Hibernate OGM since your requirements do not fit very well into a relational database anyway.

    But, if you already use a RDBMS, then it's simpler to just use JSON instead of switching to a NoSQL database just for that reason.

提交回复
热议问题