-->
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: Joins in Hibernate
PostPosted: Mon Jun 10, 2013 3:06 am 
Newbie

Joined: Sat Jan 22, 2011 2:56 am
Posts: 5
I'm using Java with Hibernate 3.

I have an sql as follows:

Code:
select sd3.id as id_3, sd2.id as id_2, sd1.id as id_1, od.id as id_0 from developer as sd3
      left outer join developer as sd2 on sd3.sr_developer_id = sd2.id
      left outer join developer as sd1 on sd2.sr_developer_id = sd1.id
      left outer join developer as od on sd1.sr_developer_id = od.id
    where sd3.id = 812


It is a case of self join.

The table structure looks like:

developer

Code:
id  | sr_developer_id
---------------------
812 | 463
463 | 8
8   | NULL


The output of the above query is:

Code:
id_3 | id_2 | id_1 | id_0
----------------------------
812  |  463 |  8   | NULL



Now I want to convert this query either in HQL or in criteria.
Can anyone help me?

Developer.java

Code:
private long id;
    private long srDeveloperID;
   
    public long getId() {
         return id;
    }
   
    public void setId(long id) {
         this.id = id;
    }
   
    public long getSrDeveloperID() {
       return srDeveloperID;
    }
   
    public void setSrDeveloper(long srDeveloperID) {
       this.srDeveloperID = srDeveloperID;
    }


Developer.hbm.xml

Code:
<?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC
       "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
       "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    <hibernate-mapping >
       <class name="com.beans.Developer" table="developer">
          <id name="id" column="id" type="long">
             <generator class="native"/>
          </id>
            <property name="srDeveloperID" column="sr_developer_id" type="long"></property>
        </class>
    </hibernate-mapping>


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.