Hibernate version: 3.2.1.ga
Database: IDS 7.3
I need to outer join a table (Product) to its self using a foreign key. I can do this in SQL and through hibernate using native SQL but I would like to be able to do it in HQL. To achieve this I need add a self referencing mapping on the entity but I have no idea how to achieve this.
I am creating my mappings using annotations.
The id for my Product entity is prodId and the foreign key I wish to map with is plantId.
@Entity
public class Product {
private Integer prodId;
private Integer plantId;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "PROD_ID", nullable = false)
public Integer getProdId() {
return prodId;
}
public void setProdId(Integer prodId) {
this.prodId = prodId;
}
@Column(name = "PLANT_ID", nullable = false)
public Integer getPlantId() {
return plantId;
}
public void setPlantId(Integer plantId) {
this.plantId = plantId;
}
This is the SQL query I wish to write in HQL
SELECT *
FROM product cb1
LEFT OUTER JOIN product cb2 ON cb1.plant_id = cb2.plant_id
WHERE cb1.man_date = :x1
AND cb2.man_date > :x2
AND cb2.man_date >= :x2
Thanks for any help with this.
|