I have the following tables:
EMPLOYEE
---------
EMPL_ID (PK)
FRST_NAME
LAST_NAME
EMP_TYP_CODE
(etc.)
CODE
---------
DOMAIN (PK part)
CODE (PK part)
DESCRPTN
Because I want to have a single code lookup table with codes partitioned by domain rather than a separate lookup table for each code, which would introduce many tables in my schema and I don't like that. So the PK in CODE is composite (DOMAIN, CODE). Imagine that the data in CODES is something like
CODE_DOMAIN CODE DESCRPTN
--------------------------------
EMP_TYP F full time
EMP_TYP P part time
EMP_TYP T temp
COMP_LEVEL A entry
COMP_LEVEL B mid
(etc.)
When linking my Employee Entity
class to the Code entity class, how do I specify that what I am interested in the CODE table is only its subset that have the DOMAIN of EMP_TYP without having a redundant DOMAIN column/field in the Employee table/class?
I tried
@ManyToOne
@JoinColumn(name = "EMP_TYP_CODE")
private Code empType;
but got
org.hibernate.AnnotationException: A Foreign key refering com.myapp.Code from com.myapp.Employee has the wrong number of column. should be 2.
Please also see the sequel to this question.