Hi,
I'm working on getting the data from two tables of DB2 database. (Contact and Address)
If I code as following in the DAO.
session.get(Contact.class,"XYZ")
Where "Contact" is the value object, containing the getter setter methods of the values of both the tables. In this class, I've defined a "Set" to get the values from Address table.
session is an object of org.hibernate.Session.
Now, after running the code using above statement, i'm getting the result from only one table (i.e. from Contact table), i'm not getting the records from Address table.
When i debug the trace, internally it's creating two collection objects instead of one. And returning one collection object which has only the values of Contact table.
If I code the DAO using Named Query
session.getNamedQuery("contactDetails").setString("param", "XYZ");
I'm getting the result from 2 tables (from Contact & Address) (what i expected).
In contact.hbm.xml file, i wrote the code for one-to-many association which returns the set of addresses.
Internally, while debugging, i could see that, the queries are generated correctly in both the cases, and they are also been executed properly, but the difference is only while returning.
Using 1st method, the return result is 2 collections. (the values in 1 collection are from only 1 table, and the other new collection for other table)
Using 2nd method (named query), the return result is 1 collection.
Could you please let me know, what changes do i need to make the code working (internally it should return 1 collection for the 1st method) using session.get() (without named query) ???
Thanx
|