I have an entity mapped to a table. This table usually has some columns on top of the mapped properties. For example if the entity is defined as:
@Entity
class MyEntity {
private String a;
}
Then the table has column a
. In one schema it may also have columns b
and c
, in another d
, e
and f
. I thought it would be simple to override EntityManager
's load
method to load all the properties defined in MyEntity
and subsequently load all the others into a Map<String, Object>
, but I can't find a way to do it.
Here's what I considered so far:
- I found this SO question, which led to this post which maybe solves the issue but requires loading the mapping on startup, which doesn't solve my problem since I'm constantly switching between schemas and therefore would have to reload the mapping over and over.
- Overriding RelationalMappingContext also assumes a constant schema.
- There should be a way to supply
EntityManager
as a bean but I can't figure out how and I'm not sure if that wouldn't run into the same issues as 1 & 2. - I can do something complicated with bytecode manipulation but this would require having an Entity per schema, which is too complicated.
- So I'm forced to consider overriding all methods in
CrudRepository
and providing my own implementation. That would be very hacky and unwieldy.
Any other ideas?