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.