Hi,
I have an issue while retrieving the data from the database using Hibernate.
This is a very simple structure. A Person object having many Address objects.
In my hbm.xml file I have stated inverse="true" and lazy="true"Code:Person { Long personId; String Name; String emailAddress; List addresses; } Address { Long personId; Long postalId; String addressLine1; }
In my PersonDAO implementation
I have a method called
If you look at the code I intentionally added log.info to print the size of the addressList.Code:public Person getPerson(String pEmailAddress) throws DataAccessException { final String query = "from webstore.domain.Person as person where " + "email_address = ?"; Object param = new Object(); param = pEmailAddress; List tmpList = getHibernateTemplate().find(query, param); if (tmpList.size() < 1) { return null; } Iterator itrOuter = tmpList.iterator(); LOGGER.info("Size of the list retrieved ="+tmpList.size()); while (itrOuter.hasNext()) { Person tmpParty =((Person)itrOuter.next()); LOGGER.info("Person First Name is "+tmpParty.getFirstName()); List addressList = tmpParty.getAddresses(); LOGGER.info("Size of the address object ="+addressList.size()); Iterator itrInner = addressList.iterator(); while(itrInner.hasNext()) { PostalAddress postAddress = (PostalAddress)itrInner.next(); LOGGER.info("Address Line1 ="+postAddress.getAddressLine1()); } } return (Person) tmpList.get(0); }
Even though for the test data that I have has only one address record, The above mention statement tells me there are 2 objects in the collection. When I did further investigation the first object is null and the second object has the right values.
Now my question is how/where does the null object gets added to the collection?
Is this a Hibernate issue or some configuration issue.
Pls help.
Thanks,
Arun


Reply With Quote