Announcement Announcement Module
Collapse
No announcement yet.
Hibernate Returning empty collection Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Hibernate Returning empty collection

    Hi,
    I am new to Hibernate and is stuck up with a problem.

    I have 2 tables University and Pincode.
    I am trying to fetch the columns of the Pincode table for the University object.
    But it is coming as empty collection.

    Can you please help me

    Thanks
    Swapan

    mapping file--

    <class name="com.uessetupdataservices.beans.University" table="UNI_SET_UNIVERSITY_MAST">
    <id name="id" column="UNIVERSITY_ID">
    <generator class="assigned"/>
    </id>
    <property name="universityCode" column="UNIVERSITY_CODE"/>
    <property name="universityName" column="UNIVERSITY_NAME"/>

    <set name="pincodes" table="UNI_SET_PINCODE_MAST" lazy="false" >
    <key column="PINCODE" />
    <one-to-many class="com.uessetupdataservices.beans.Pincodes" />
    </set>
    </class>

    <class name="com.uessetupdataservices.beans.Pincodes" table="UNI_SET_PINCODE_MAST" >
    <id name="id" column="PINCODE">
    <generator class="assigned"/>
    </id>
    <property name="cityId" column="CITY_ID"/>
    <property name="districtId" column="DISTRICT_ID"/>
    </class>


    Client Code--
    public class UniversityDao implements IUniversityDao {
    private DataFactory dataFactory;
    public void setDataFactory(DataFactory dataFactory) {
    this.dataFactory = dataFactory; }

    public University[] getUniversity() {
    String query="from University university";
    University[] UniversityObj = (University[])dataFactory.getEntity(query);
    return UniversityObj; }}

    public class DataFactory extends HibernateDaoSupport {
    public Object[] getEntity(String query) {
    Object[] obj = null;
    HibernateTemplate hibernateTemplate = getHibernateTemplate();
    List l = hibernateTemplate.find(query);
    obj = new Object[l.size()];
    for(ListIterator it=l.listIterator();it.hasNext(){
    obj[it.nextIndex()]=it.next();}
    return obj; }
    }

    The stacktrace --

    4766 [main] DEBUG org.hibernate.SQL - select university0_.UNIVERSITY_ID as UNIVERSITY1_0_, university0_.UNIVERSITY_CODE as UNIVERSITY2_0_, university0_.UNIVERSITY_NAME as UNIVERSITY3_0_, university0_.UNIVERSITY_SHORT_NAME as UNIVERSITY4_0_, university0_.UNIVERSITY_TYPE as UNIVERSITY5_0_, university0_.DATE_OF_ESTABLISHMENT as DATE6_0_, university0_.GOVT_RESOLUTION_NO as GOVT7_0_, university0_.GOVT_RESOLUTION_DATE as GOVT8_0_, university0_.ACCREDIATION_LEVEL as ACCREDIA9_0_, university0_.ACCREDIATION_AGENCY as ACCREDI10_0_, university0_.HISTORY as HISTORY0_, university0_.ADDRESS1 as ADDRESS12_0_, university0_.ADDRESS2 as ADDRESS13_0_, university0_.AREA_NAME as AREA14_0_, university0_.PINCODE as PINCODE0_, university0_.WEBSITE as WEBSITE0_, university0_.EMAIL_ID as EMAIL17_0_, university0_.PHONE1 as PHONE18_0_, university0_.PHONE2 as PHONE19_0_, university0_.PHONE3 as PHONE20_0_, university0_.PHONE4 as PHONE21_0_, university0_.PHONE5 as PHONE22_0_, university0_.PHONE6 as PHONE23_0_, university0_.CREATED_BY as CREATED24_0_, university0_.CREATED_DATE as CREATED25_0_, university0_.MODIFIED_BY as MODIFIED26_0_, university0_.MODIFIED_DATE as MODIFIED27_0_, university0_.RECORD_STATUS as RECORD28_0_ from UNI_SET_UNIVERSITY_MAST university0_
    Hibernate: select university0_.UNIVERSITY_ID as UNIVERSITY1_0_, university0_.UNIVERSITY_CODE as UNIVERSITY2_0_, university0_.UNIVERSITY_NAME as UNIVERSITY3_0_, university0_.UNIVERSITY_SHORT_NAME as UNIVERSITY4_0_, university0_.UNIVERSITY_TYPE as UNIVERSITY5_0_, university0_.DATE_OF_ESTABLISHMENT as DATE6_0_, university0_.GOVT_RESOLUTION_NO as GOVT7_0_, university0_.GOVT_RESOLUTION_DATE as GOVT8_0_, university0_.ACCREDIATION_LEVEL as ACCREDIA9_0_, university0_.ACCREDIATION_AGENCY as ACCREDI10_0_, university0_.HISTORY as HISTORY0_, university0_.ADDRESS1 as ADDRESS12_0_, university0_.ADDRESS2 as ADDRESS13_0_, university0_.AREA_NAME as AREA14_0_, university0_.PINCODE as PINCODE0_, university0_.WEBSITE as WEBSITE0_, university0_.EMAIL_ID as EMAIL17_0_, university0_.PHONE1 as PHONE18_0_, university0_.PHONE2 as PHONE19_0_, university0_.PHONE3 as PHONE20_0_, university0_.PHONE4 as PHONE21_0_, university0_.PHONE5 as PHONE22_0_, university0_.PHONE6 as PHONE23_0_, university0_.CREATED_BY as CREATED24_0_, university0_.CREATED_DATE as CREATED25_0_, university0_.MODIFIED_BY as MODIFIED26_0_, university0_.MODIFIED_DATE as MODIFIED27_0_, university0_.RECORD_STATUS as RECORD28_0_ from UNI_SET_UNIVERSITY_MAST university0_
    4907 [main] DEBUG org.hibernate.jdbc.AbstractBatcher - about to open ResultSet (open ResultSets: 0, globally: 0)
    4938 [main] DEBUG org.hibernate.loader.Loader - result row: EntityKey[com.uessetupdataservices.beans.University#1]
    4954 [main] DEBUG org.hibernate.loader.Loader - result row: EntityKey[com.uessetupdataservices.beans.University#2]
    4954 [main] DEBUG org.hibernate.jdbc.AbstractBatcher - about to close ResultSet (open ResultSets: 1, globally: 1)
    4954 [main] DEBUG org.hibernate.jdbc.AbstractBatcher - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
    4969 [main] DEBUG org.hibernate.engine.TwoPhaseLoad - resolving associations for [com.uessetupdataservices.beans.University#1]
    4985 [main] DEBUG org.hibernate.engine.TwoPhaseLoad - done materializing entity [com.uessetupdataservices.beans.University#2]
    4985 [main] DEBUG org.hibernate.engine.StatefulPersistenceContext - initializing non-lazy collections
    5000 [main] DEBUG org.hibernate.loader.Loader - loading collection: [com.uessetupdataservices.beans.University.pincodes #2]
    5000 [main] DEBUG org.hibernate.jdbc.AbstractBatcher - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
    5000 [main] DEBUG org.hibernate.SQL - select pincodes0_.PINCODE as PINCODE1_, pincodes0_.PINCODE as PINCODE1_0_, pincodes0_.CITY_ID as CITY2_1_0_, pincodes0_.DISTRICT_ID as DISTRICT3_1_0_, pincodes0_.STATE_ID as STATE4_1_0_, pincodes0_.COUNTRY_ID as COUNTRY5_1_0_, pincodes0_.CREATED_BY as CREATED6_1_0_, pincodes0_.CREATED_DATE as CREATED7_1_0_, pincodes0_.MODIFIED_BY as MODIFIED8_1_0_, pincodes0_.MODIFIED_DATE as MODIFIED9_1_0_, pincodes0_.RECORD_STATUS as RECORD10_1_0_ from UNI_SET_PINCODE_MAST pincodes0_ where pincodes0_.PINCODE=?
    Hibernate: select pincodes0_.PINCODE as PINCODE1_, pincodes0_.PINCODE as PINCODE1_0_, pincodes0_.CITY_ID as CITY2_1_0_, pincodes0_.DISTRICT_ID as DISTRICT3_1_0_, pincodes0_.STATE_ID as STATE4_1_0_, pincodes0_.COUNTRY_ID as COUNTRY5_1_0_, pincodes0_.CREATED_BY as CREATED6_1_0_, pincodes0_.CREATED_DATE as CREATED7_1_0_, pincodes0_.MODIFIED_BY as MODIFIED8_1_0_, pincodes0_.MODIFIED_DATE as MODIFIED9_1_0_, pincodes0_.RECORD_STATUS as RECORD10_1_0_ from UNI_SET_PINCODE_MAST pincodes0_ where pincodes0_.PINCODE=?
    5016 [main] DEBUG org.hibernate.jdbc.AbstractBatcher - about to open ResultSet (open ResultSets: 0, globally: 0)
    5016 [main] DEBUG org.hibernate.loader.Loader - result set contains (possibly empty) collection: [com.uessetupdataservices.beans.University.pincodes #2]
    5016 [main] DEBUG org.hibernate.jdbc.AbstractBatcher - about to close ResultSet (open ResultSets: 1, globally: 1)
    5016 [main] DEBUG org.hibernate.jdbc.AbstractBatcher - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
    5016 [main] DEBUG org.hibernate.engine.loading.CollectionLoadContext - 1 collections were found in result set for role: com.uessetupdataservices.beans.University.pincodes
    5016 [main] DEBUG org.hibernate.engine.loading.CollectionLoadContext - collection fully initialized: [com.uessetupdataservices.beans.University.pincodes #2]
    5016 [main] DEBUG org.hibernate.engine.loading.CollectionLoadContext - 1 collections initialized for role: com.uessetupdataservices.beans.University.pincodes
    5016 [main] DEBUG org.hibernate.loader.Loader - done loading collection
    5047 [main] DEBUG org.hibernate.jdbc.ConnectionManager - transaction completed on session with on_close connection release mode; be sure to close the session to release JDBC resources!

  • #2
    It might have helped to see the table definitions, but it looks to me like these two tables are independent, with no obvious relationship between them. The "pincodes" set definition makes no sense. The "key" element in the set specifies the column that refers back to the parent table, not the column inside the referred-to table.

    Comment


    • #3
      Yeah...u r correct...i changed it to University_FK and it worked....

      Thanx a lot...

      Comment

      Working...
      X