Let's say I have the following example entities - one is an @Embeddable
, embedded inside another @Entity
:
@Embeddable
public class ContactInfoEntity {
@Column
private String phone;
@Column
private String zipCode;
}
@Entity
@Table(name = "EMPLOYEE")
public class EmployeeEntity {
@Id
@Column(name = "EMPLOYEE_ID")
private Long employeeId;
@Embedded
@AttributeOverrides({
@AttributeOverride(name = "phone",
column = @Column(name = "EMPLOYEE_PHONE")),
@AttributeOverride(name = "zipCode",
column = @Column(name = "EMPLOYEE_ZIP_CODE"))
})
private ContactInfoEntity employeeContactInfo;
}
The meta-model classes generated by the openjpa-maven-plugin include only an employeeContactInfo
variable, not the @AttributeOverride
columns.
Now suppose I want to do this:
Select the
EMPLOYEE_ID
andEMPLOYEE_PHONE
where theEMPLOYEE_ZIP_CODE
is equal to "123456"
How do I create this as a CriteriaQuery
?
CriteriaBuilder cb = entityManager.getCriteriaBuilder();
CriteriaQuery<String> qDef = cb.createQuery(String.class);
Root<EmployeeEntity> e = qDef.from(EmployeeEntity.class);
qDef.select(e.get(EmployeeEntity_.employeeId),
e.get(????))
.where(cb.equal(e.get(????), "123456"));
return entityManager.createQuery(qDef).getResultList();
ContactInfoEntity
andEmployeeEntity
related? Shouldn'tResourceNodeEntity
be replaced withContactInfoEntity
? – Inly