-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: How to write named native subqueries?
PostPosted: Mon Jul 25, 2011 12:03 pm 
Newbie

Joined: Mon Jul 25, 2011 11:52 am
Posts: 1
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

company

Code:
@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_rel

Code:
@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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.