Hibernate version: 2.0
I have the following relational mapping:
"A Property has an Address which has a Postcode which has a locality (of type String)".
These relationships are mapped using a many-to-one.
I'm trying to construct a query to select Property types by using the Criteria API (Chapter 12 of the Reference)
and specifying a value for the postcode. All of my attempts so far have failed.
Here is an example of what I am trying to achieve unsuccessfully:
Code:
Criteria crit = session.createCriteria(Property.class);
crit.createAlias("address", "a")
.add(Expression.eq("a.postcode.locality", "The Locality"));
This results in the following error:
Quote:
net.sf.hibernate.QueryException: could not resolve property: postcode.locality of: com.tmits.web.re.dao.Address.
I've tried everything that I can think of to achieve a solution.
Assistance is most appreciated.
Appendix
--------
Using XDoclet, the code looks something like the following.
It has been trimmed for brevity (this question is already long) but effort has made to not trim appropriate parts.
If anyone feels it is appropriate to construct a complete test case and leave it unaltered, I will do so.
Code:
public class Property
{
private Long id;
private Address address;
public Property()
{
this(null);
}
public Property(Long id)
{
this.id = id;
}
/**
* Returns the id attribute of this property.
* This attribute is used as a unique identifier.
*
* @return The id attribute of this property.
* @hibernate.id generator-class="native"
*/
public final Long getId()
{
return id;
}
public final void setId(Long id)
{
this.id = id;
}
/**
* Returns the address attribute of this property.
*
* @return The address attribute of this property.
* @hibernate.many-to-one name="address"
*/
public final Address getAddress()
{
return address;
}
public final void setAddress(Address address)
{
this.address = address;
}
}
/**
* A Data Access Object (DAO) that represents an address.
*/
public class Address
{
private Long id;
private Postcode postcode;
public Address()
{
this(null);
}
public Address(Long id)
{
this.setId(id);
}
/**
* Returns the id attribute of this address.
* This attribute is used as a unique identifier.
*
* @return The id attribute of this address.
* @hibernate.id generator-class="native"
*/
public final Long getId()
{
return id;
}
public final void setId(Long id)
{
this.id = id;
}
/**
* Returns the postcode attribute of this address.
*
* @return The postcode attribute of this address.
* @hibernate.many-to-one name="postcode"
*/
public final Postcode getPostcode()
{
return postcode;
}
public final void setPostcode(Postcode postcode)
{
this.postcode = postcode;
}
}
/**
* A Data Access Object (DAO) that represents a postcode.
*/
public class Postcode
{
private Long id;
private String locality;
public Postcode()
{
this(null);
}
public Postcode(Long id)
{
this.setId(id);
}
/**
* Returns the id attribute of this postcode.
* This attribute is used as a unique identifier.
*
* @return The id attribute of this postcode.
* @hibernate.id generator-class="native"
*/
public final Long getId()
{
return id;
}
public final void setId(Long id)
{
this.id = id;
}
/**
* Returns the locality attribute of this postcode.
*
* @return The locality attribute of this postcode.
* @hibernate.property
* @hibernate.column name="locality"
*/
public final String getLocality()
{
return locality;
}
public final void setLocality(String locality)
{
this.locality = locality;
}
}