Hi,
I have given a task to write a named native subquery like
Code:
select c.comp_name from company c where c.cid = (select cid from com_usr_rel where uid=1100)
The entities are
companyCode:
@Entity
public class Company implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="company_id")
private String companyId;
@Column(name="apartment_no")
private BigDecimal apartmentNo;
private String city;
@Column(name="company_name")
private String companyName;
//bi-directional many-to-one association to CompanyUser
@OneToMany(mappedBy="company")
private List<CompanyUser> companyUsers;
public Company() {
}
public String getCompanyId() {
return this.companyId;
}
public void setCompanyId(String companyId) {
this.companyId = companyId;
}
public BigDecimal getApartmentNo() {
return this.apartmentNo;
}
public void setApartmentNo(BigDecimal apartmentNo) {
this.apartmentNo = apartmentNo;
}
public String getCity() {
return this.city;
}
public void setCity(String city) {
this.city = city;
}
public String getCompanyName() {
return this.companyName;
}
public void setCompanyName(String companyName) {
this.companyName = companyName;
}
public List<CompanyUser> getCompanyUsers() {
return this.companyUsers;
}
public void setCompanyUsers(List<CompanyUser> companyUsers) {
this.companyUsers = companyUsers;
}}
com_usr_relCode:
@Entity
@Table(name="com_usr_rel")
public class CompanyUser implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="com_usr_rel_id")
private String comUserId;
//bi-directional many-to-one association to Company
@ManyToOne
@JoinColumn(name="company_id")
private Company company;
//bi-directional many-to-one association to User
@ManyToOne
@JoinColumn(name="user_id")
private User user;
public CompanyUser() {
}
public String getCom_usr_relId() {
return this.comUserId;
}
public void setCom_usr_relId(String com_usr_relId) {
this.comUserId = comUserId;
}
public Company getCompany() {
return this.company;
}
public void setCompany(Company company) {
this.company = company;
}
public User getUser() {
return this.user;
}
public void setUser(User user) {
this.user = user;
}
}
Can anybody help me.
Thanks in advance