-->
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.  [ 2 posts ] 
Author Message
 Post subject: How to use HQL to retrieve a ManyToMany mapping ?
PostPosted: Sat Mar 07, 2009 5:40 pm 
Newbie

Joined: Sat Mar 07, 2009 5:23 pm
Posts: 1
Hi there,

Apologies if answered before, had a look but could not find it.

I have a m2m relationship between two tables business and rewards_shceme, these are setup via annotation in two classes Business and RewardsScheme. They generate a third table called biz_rwd_jn to hold the mappings.

I have been trying to get the following hql to work to no avail;

Code:
String temp = "Business_1";
Session session = HibernateUtil.getSession();
String hql = "from Business where name = :busName";
Query query = session.createQuery(hql);
query.setString("busName",temp);
Object obj = query.uniqueResult();
Business business = (Business)obj;
hql = "from RewardsScheme s join s.business where s.business = :biz";
query.setParameter("biz", business);
List obj1 = query.list();


s.business is the List of business held in the RewardScheme class i.e.
Code:
   @ManyToMany
   @JoinTable(name = "biz_rwd_jn",
         joinColumns = {@JoinColumn(name = "rwdSch_id")},
         inverseJoinColumns = {@JoinColumn(name = "business_id")}
   )
   public List<Business> getBusiness() {
      return business;
   }
   public void setBusiness(List<Business> business) {
      this.business = business;
   }
   public void addBusiness(Business business) {
      this.business.add(business);
   }


Am going a bit nuts with this , its does retrieve the correct unique Business object ok but keeps giving me the following error when trying to get the RewardsScheme objects

Quote:
Exception in thread "main" org.hibernate.QueryParameterException: could not locate named parameter [biz]



Any ideas ?

Thanks,
Mully


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 08, 2009 8:21 am 
Newbie

Joined: Sat Mar 07, 2009 4:24 am
Posts: 10
Try as follows:
Code:
String temp = "Business_1";
Session session = HibernateUtil.getSession();
List obj1 = session.createQuery("select s from RewardsScheme s join s.business as bz where bz.name like :bizName")
                .setString("bizName",temp)
                .list();


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

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.