jeudi 12 mars 2015

Using an @Embeddable entity in a JPA CriteriaQuery



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 ResourceNodeEntity employeeContactInfo;
}


Now suppose I want to do this:



Select the EMPLOYEE_ID and EMPLOYEE_PHONE where the EMPLOYEE_ZIP_CODE is equal to "123456"



The meta-model classes generated by the openjpa-maven-plugin include only an employeeContactInfo variable, not the actual required columns.


So how do I create this as a CriteriaQuery which includes these @AttributeOverride columns?




Aucun commentaire:

Enregistrer un commentaire