I need to customize the hibernate's CRUD operations to execute some extra operations. My problem is, I do not have access to change the entities implementation and I need to persist extra metadata for these entities. For example:
@Entity
class Entity1 {
@Id
private Long id;
private String attr1;
}
@Entity
class Entity2 {
@Id
private Long id;
private String attr1;
private String attr2;
}
Entity1
and Entity2
are persisted in their own tables, thats fine, but I need to persist a metadata information, lets say forced = [true|false]
, that describes if a given String
attribute was forced or not. This information will be applied over the whole system, it means, for all entities with String
attributes it should be possible to indentify it their String attributes were forced or not.
In my case, I can identify what instances and attributes were forced or not in runtime, this information is easily acessible in case I must implement some callback listener or interceptor. My idea is to persist these metadata information in a separate table, lets say FORCED_ATTRIBUTES
, that has three columns (two to identify the entity and attributes changed and another one to define if the value was changed or not).
Is it possible to get such functionality without change these entities (Entity1
and Entity2
)?