-->
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.  [ 1 post ] 
Author Message
 Post subject: Self referencing join on FK using annotations.
PostPosted: Wed Oct 29, 2008 7:58 am 
Newbie

Joined: Mon Aug 18, 2008 10:19 am
Posts: 5
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.


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

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.