I have the following class:
Code:
public class Organization {
private static Log log = LogFactory.getLog(Organization.class);
private int orgId;
private String orgName;
private String orgComp;
private Date orgActivationDate;
private Date orgInactivationDate;
private Location orgLocation;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="ORG_ID")
public int getOrgId() {
return orgId;
}
public void setOrgId(int orgId) {
this.orgId = orgId;
}
@Column(name="ORG_NAME")
public String getOrgName() {
return orgName;
}
public void setOrgName(String orgName) {
this.orgName = orgName;
}
@Column(name="ORG_COMP")
public String getOrgComp() {
return orgComp;
}
public void setOrgComp(String orgComp) {
this.orgComp = orgComp;
}
@Column(name="ACT_DATE")
public Date getOrgActivationDate() {
return orgActivationDate;
}
public void setOrgActivationDate(Date orgActivationDate) {
this.orgActivationDate = orgActivationDate;
}
@Column(name="INACT_DATE")
public Date getOrgInactivationDate() {
return orgInactivationDate;
}
public void setOrgInactivationDate(Date orgInactivationDate) {
this.orgInactivationDate = orgInactivationDate;
}
@OneToOne(mappedBy = "locationId", fetch=FetchType.LAZY, cascade=CascadeType.ALL)
public Location getOrgLocation() {
return orgLocation;
}
public void setOrgLocation(Location orgLocation) {
this.orgLocation = orgLocation;
}
I need to populate it via a Native Query. I created the following @SqlResultSetMapping:
Code:
@SqlResultSetMapping(name="explicit", entities={
@EntityResult(entityClass = Organization.class, fields= {
@FieldResult(name="orgId", column="ORG_ID"),
@FieldResult(name="orgName", column="ORG_NAME"),
@FieldResult(name="orgComp", column="ORG_COMP"),
@FieldResult(name="orgActivationDate", column="ACT_DATE"),
@FieldResult(name="orgInactivationDate", column="INACT_DATE")
}),
@EntityResult(entityClass = Location.class, fields= {
@FieldResult(name="locationId", column="LOC_ID"),
@FieldResult(name="locationName", column="LOC_NAME")
})
})
So, I can create a native query to return those fields. The above mapping will create an Organization and Location object. However, since the Location is an attribute of Organization, I don't know how to set the Location to the returned result.
Can anyone help?