Is it possible to change the target table for a Hibernate mapping? My use case is that while I get the data from one table, in cases where the data cannot be processed it is stored in a error table for later analysis.
Although it is possible to define entity-names in hibernate mappings, in my opinion it is not appropriate because it requires duplication of mappings. The same mapping would then exist for getting the data and a copy of it with a different entity-name for the error table.
Do you have any ideas how to approach and solve this problem?
Short answer – no. Defining a separate mapping (via entity name) is the way to go.
Long answer – it’s possible via runtime manipulation of Configuration prior to SessionFactory being built. You can get the mapping for the entity in question from Mappings as defined in Configuration, copy it under new entity name and associate it with a copy of the underlying Table under the new name. You would in effect still be defining a separate mapping, but doing it the hard way.
Take a look at this question.