Suppose I have the following table:
PARAMETER
- NAME varchar2(10)
- TABLE_NAME varchar2(50)
- REF_TABLE_ID number(10)
- VALUE varchar2(100)
This table holds parameter values for other tables for example if I have a table
named EMPLOYEE and I want to add a parameter to the employee with the ID 1 the
PARAMETER table will have a row as follows:
insert into PARAMETER (NAME, TABLE_NAME, REF_TABLE_ID, VALUE) values ('PARAM1', 'EMPLOYEE', 1, 'Value of PARAM1');
Ofcourse this does not force any integrety constraint, but this PARAMETER table cannot be changed.
Now I want to map this PARAMETER table in my entity EMPLOYEE, what I need is something to replace (@SomeAnnotation)
public class Employee {
@OneToMany
@JoinColumn(name="REF_TABLE_ID")
@SomeAnnotation("and table_name = 'EMPLOYEE'")
private List<Parameter> parameters;
... etc
}
For now I am using a @PostLoad annotation to load all PARAMETER’s related to this entity, but I would prefer if I could
map the PARAMETER Table somehow.
Another Idea I am having is to create a VIEW where I filter the PARAMETER table for TABLE_NAME = ‘EMPLOYEE’ but this means
that I will need to create a view for all my tables in the DB and they too much.
any thoughts?
You’re looking for the @Where annotation. You don’t need the
andin the clause, AFAIK.