Dynamic models without using HBM

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.

Do you really need to allow adding columns to table?

Because it sounds like a niche for NoSql schemaless DB ))

I don’t believe that you allow to extent every table. Extension is usually required for few tables and it can be done with a signature:

CREATE TABLE book_ext (
  book_id bigint,
  name text,  -- defines "column" name & type ))
  int_val integer,
  date_val timestamp,
  string_val text)

This way you’ll have infinite number of extension columns and still live in relational data model that Hibernate can manage for you…