0

My team is looking to use the Hibernate ORM in a new Java server we are developing for our product.

We allow clients to extend our database schema by adding their own custom columns. The columns are added at runtime, and they are added directly to the underlying database table, i.e. the schema is changed. Data specifying the schema changes are stored in a separate table, detailing the affected tables/columns.

Ultimately, we cannot specify the custom columns via JPA annotations because they are not known at compile time, but we still need to CRUD these columns. We would like to use all of Hibernate’s underlying niceties to handle the reads and writes.

What’s the proper way to do this in modern Hibernate? We saw that in the old HBM file format there is a certain that (sort of) meets our needs, but we also understand that HBM is deprecated. We’d appreciate any pointers.

8
  • Might have to utilize hibernates native sql functionality for your CRUD operations. Store the custom column names in a managed table and create your queries off from those columns. Commented Jul 15, 2020 at 14:33
  • Look at dynamic mapping models. Commented Jul 15, 2020 at 14:41
  • @SternK The documentation there references an HBM file, which we are trying to avoid since they're deprecated. Also, if we were to add a new column to an entity, we would have to regenerate the XML file somehow. Do you know of a way to accomplish the dynamic model mapping without HBM files? Commented Jul 15, 2020 at 15:15
  • @locus2k If that were the case, then we'd want to hook into the SQL generation statements hibernate is building and overwrite them. Otherwise we'd require a additional update statement for the dynamic columns. Do you know where this hook could happen, or have you done it before? Commented Jul 15, 2020 at 15:17
  • @Albert Have you seen this? It looks like this is not solvable task in the hibernate scope. Commented Jul 15, 2020 at 15:38

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.