For more context, please see my other question.
I want to join my Employee
entity class to Code
entity class but the Code PK is composite (
This should work?
@JoinColumn(name = "EMP_TYPE_CODE", referencedColumnName = "CODE")
@Where(clause = "domain = 'EMP_TYPE'")
@ManyToOne(optional = false)
private Code sharedStatute;
Note: Apparantly this solution is OpenJPA only.
There is a way to do this with javax.persistence annotations only:
@JoinColumns({
@JoinColumn(name = "EMP_TYPE_CODE", referencedColumnName = "CODE"),
@JoinColumn(name = "CODE_TABLE_NAME.DOMAIN", referencedColumnName = "'EMP_TYPE'")})
@ManyToOne(optional = false)
private Code sharedStatute;
Note the single quotes in the referencedColumnName, this is the String value you are looking for.
There is a downside however, when you have multiple Code objects in your entity, the join on DOMAIN will be done only once in jpa, giving bad results. At the moment I circumvent this by making those field load lazily, but that's not ideal.
More information here.