Announcement Announcement Module
Collapse
No announcement yet.
how to retrieve value from hibernate join queries Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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, 11:04 AM.

    Comment


    • #3
      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

      Comment


      • #4
        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, 11:03 AM.

        Comment


        • #5
          Thank you

          Thank you very much.
          It is working well.

          Comment


          • #6
            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, 11:03 AM.

            Comment

            Working...
            X