Results 1 to 6 of 6

Thread: how to retrieve value from hibernate join queries

  1. #1
    Join Date
    Apr 2007
    Posts
    16

    Default how to retrieve value from hibernate join queries

    Any one could help me in retrieving values from hibernate join queries!!!

    The query in dao is

    public List findSitebySystem(int sapSystemId)throws DataAccessException{

    List sitebySystem=new ArrayList();

    try{

    sitebySystem=getHibernateTemplate().find("select s.siteName,s.siteId from TSite s,TSapsystem ss where ss.sapSystemId= s.sap_system_id and s.sap_system_id=1");


    }catch(Exception e){
    SecureSapLogger.error("Exception in findSitebySystem :: SiteDAO "+e,SiteDAO.class);
    throw new DataAccessException("Exception in findSitebySystem :: SiteDAO");
    }
    return sitebySystem;
    }

    and the mapping hbm.xml is

    <class name="com.securesap.hibernate.model.TSite" table="t_site" lazy="false">
    <comment></comment>
    <id name="siteId" type="int">
    <column name="site_id" />
    <generator class="identity" />
    </id>
    <property name="siteName" type="string">
    <column name="site_name" length="30" not-null="true">
    <comment></comment>
    </column>
    </property>
    <property name="sap_system_id" column="sap_system_id" type="int" not-null="true"></property>

    <property name="city" type="string">
    <column name="city" length="30" not-null="true">
    <comment></comment>
    </column>
    </property>
    <property name="state" type="string">
    <column name="state" length="30" not-null="true">
    <comment></comment>
    </column>
    </property>
    <property name="zip" type="string">
    <column name="zip" length="30" not-null="true">
    <comment></comment>
    </column>
    </property>
    <property name="plantCode" type="string">
    <column name="plant_code" length="30">
    <comment></comment>
    </column>
    </property>
    <property name="dateCreated" type="date">
    <column name="date_created" length="19" not-null="true">
    <comment></comment>
    </column>
    </property>
    <property name="dateModified" type="date">
    <column name="date_modified" length="19" not-null="true">
    <comment></comment>
    </column>
    </property>
    <set name="TSaproleBySapsystemAndSites" >
    <key>
    <column name="site_id" not-null="true">
    <comment></comment>
    </column>
    </key>
    <one-to-many class="com.securesap.hibernate.model.TSaproleBySap systemAndSite" />
    </set>
    <set name="TUsers" inverse="true">
    <key>
    <column name="site_id" not-null="true">
    <comment></comment>
    </column>
    </key>
    <one-to-many class="com.securesap.hibernate.model.TUser" />

    </set>

    I could get the result in eclipse hibernate console. I have retrieved a value in sitebySystem List .But i dont have a idea that how the values are stored in a list also how can i display the siteName and siteId from the List.

    Help me regarding this.

    I dont get any exception or error also no result.

    Thanks in advance.

  2. #2
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    I'm not sure what the question is, but I'd presume you're confused about what type the query is actually returning. It's actually List<Object[]>.
    Last edited by karldmoore; Aug 29th, 2007 at 10:04 AM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

  3. #3
    Join Date
    Apr 2007
    Posts
    16

    Default Thank you but i dont know how to display.

    Thank you very much for sending a valuable reply to me.

    It will return Object[].But i dont know how to print the values from the that.

    Do you have any examples for that .

    Please help me for that .

    thanks in advance

  4. #4
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    Not exactly sure what you are trying to do but........
    Code:
    List<Object[]> values = null; // blah
    for (Object[] value : values) {
        for (Object object : value) {
            System.out.println (object);
        }
    }
    Last edited by karldmoore; Aug 29th, 2007 at 10:03 AM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

  5. #5
    Join Date
    Jul 2007
    Posts
    25

    Default Thank you

    Thank you very much.
    It is working well.

  6. #6
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    Glad to help, if you are interested there's some more information here on what you can do with a SELECT cause. Some of it is quite clever.
    http://www.hibernate.org/hib_docs/v3...ueryhql-select
    Last edited by karldmoore; Aug 29th, 2007 at 10:03 AM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •