I am trying to join to different entities from the same table using a constant value in the join statement. In SQL, I would do something like this...
SELECT
If you don't mind using Hibernate-specific annotations you could try with the @WhereJoinTable
annotation, e.g.:
@OneToOne(mappedBy = "owner", fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinColumn(name = "ID", referencedColumnName = "ID")
@WhereJoinTable(clause = "TYPE = 'A'")
private TypeA inspectionSnapshot;
Note that the clause
attribute must contain SQL, not JPQL, so you need to use the database column name instead of the JPA entity field name.
Try to specify a constant as the value of the formula
@JoinColumnsOrFormulas({
@JoinColumnOrFormula(formula=@JoinFormula(value="'A'", referencedColumnName="type")),
@JoinColumnOrFormula(column = @JoinColumn("id", referencedColumnName="id"))
})
private TypeA inspectionSnapshot;
You're looking at non-standard joins. Here's the documentation for treating such a case:
http://docs.oracle.com/cd/E13189_01/kodo/docs40/full/html/ref_guide_mapping_notes_nonstdjoins.html
Hope it helps!