Is there a way to map Hibernate to a column that may or may not exist?

I have a situation where a table column may or may not exist. In short, we have an additional function that, if implemented, will be bound to a column in a table. If the client does not want to have this function, they will not have a column.

I am trying to define a property in my DAO for it, in the hope that Hibernate will not explode if there is no column there. Perhaps setting null . But Hibernate throws an "invalid id" exception.

Does anyone know if you can do this? Have a column mapping, if a column there Hibernate fills it, but if it is not present, is everything ok and is it just null ?

Thank you very much.

+4
source share
1 answer

The most obvious option is to create different mappings and select one of them during startup, depending on the environment.

Depending on how you configure Hibernate, you can use some options to avoid duplication between different mappings:

  • If you use .hbm.xml , you can apply some preprocessing to it.
  • If you use annotations, you can override them using configuration files in the orm.xml syntax
+2
source

Source: https://habr.com/ru/post/1338951/


All Articles