-->
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: HQL on one-to-many relationships
PostPosted: Thu Mar 01, 2007 11:06 am 
Newbie

Joined: Thu Mar 01, 2007 10:43 am
Posts: 2
Suppose I have the following small DB which defines two classes A and B, where B contains a set of As with a one-to-many relationship, eg:

Code:
/**
* @hibernate.class table="as"
*/
public class A
{
    public A()
    {
    }

    /**
     * @hibernate.id column="id" not-null="true" generator-class="native"
     */
    public Integer getId() { return id;   }
    public void setId(Integer id) { this.id = id; }
    private Integer id;
   
   /**
    * @hibernate.property column="name"
    */
   public String getName() { return name; }
   public void setName(String name) { this.name = name; }
   private String name;
}

/**
* @hibernate.class table="bs"
*/
public class B
{
    public B()
    {
    }

    /**
     * @hibernate.id column="id" not-null="true" generator-class="native"
     */
    public Integer getId() { return id;   }
    public void setId(Integer id) { this.id = id; }
    private Integer id;
   
    /**
     * @hibernate.set lazy="true"
     * @hibernate.collection-one-to-many class="A"
     * @hibernate.collection-key column="b"
     */
    public Set getAs() { return this.as; }
    public void setAs(Set as)
    { this.as = as; }
    private Set as;
}


This creates two tables as such:

Code:
Table name  Columns
----------  -------
as          id,name,b
bs          id


Such that any entry in as can have a parent from bs.
I want to write a query that gives me all children of a particular b where id = x and name = n, eg.

select * from as where name = n and b = x

This works fine, but my question is: How do I do this in HQL?
I have tried:

from A a where a.name = n and a.b = x

But I just get an error resolving a.b.

Help is very much appreciated.
Thanks,
Chris.


Top
 Profile  
 
 Post subject: Fixed
PostPosted: Thu Mar 01, 2007 12:35 pm 
Newbie

Joined: Thu Mar 01, 2007 10:43 am
Posts: 2
I've fixed it now - thanks.


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.