Home > Enterprise >  Dynamic number of fields in database at runtime
Dynamic number of fields in database at runtime

Time:11-05

I am currently developing a spring boot application with a database for patient data. I would really like to use spring's JPA as I am familiar with it but there is a problem I have with no satisfying solution for.

The problem is, that I, e.g., have several parameters from a blood work sample. These will be saved to the DB. But in the future, these parameters might change and I would have to add new parameters and persist them in my DB. Unfortunately, I am not the person entering all the data by hand but just the person writing the application.

Is there any way to dynamically add a column on runtime to the database and spring application without having to change any source code (so basically a user could press a button: "Add parameter 'xy'"?

If not, I was thinking about another approach where instead of saving entries as follows:

| PatientID | param1 | param2 | param3 | ... |

I would save them like this:

| PatientID | ParameterType | Value | Date     |
| 1         | param1        | 10    | 1.1.2021 |
| 1         | param2        | 15    | 1.2.2021 |
...

With this solution, I am a bit scared of query performance once a lot of entries are present. And additionally, a lot of extra logic would be needed for fairly simple queries.

I would really appreciate any input you can give me, even completely different approaches

CodePudding user response:

I would recommend you store document instead of entity. For that you can use Spring-data-couchbase because we don't know the data structure.

You can explore SQL vs noSQL

  • Related