| Author |
Problem in hibernate join result
|
vinoth subramaniam
Ranch Hand
Joined: Jul 05, 2008
Posts: 47
|
|
Hi all, I am trying to fetch some information from two tables in the database. I used the inner join, and i can able to get the data from the database. The only problem is the resulted data is not in the way i expected. Please see the code here. Table Striucture And the CONTACT and person class have one to many relationship according to the business logic. I.e for one contact there may be one or more streets (just for some testing purpouse i wrote like that..) Here is the CONTACT class And here is the person class And here is the hbm.xml file for the CONTACT class And here is the hbm.xml file for person class And i am using the following classes to get the data The using sessionfactory class The resulted list have the three CONTACT object, in which each one have the persons list object. That particular persons list have no of person object. Resulted List == [CONTACT OBJ, ....] | | [ID, FirstName, Persons] | | [Person OBJ, person OBJ] | | [Street, personID] The part of the result in the console as follows But i need the result in the following way Size of the list 3 9 Antony North Street 2 selvaraj North Street 2 Selvaraj Kallur Street Because i want to display this data in a table. Where i need to change, Is there any modification needed in the Mapping or in the hql query or in the classes declaration. Please help me to solve this issue. Thanks in advance ..!
|
 |
vinoth subramaniam
Ranch Hand
Joined: Jul 05, 2008
Posts: 47
|
|
Can you please anyone respond to this question please...!
|
 |
Kuladip Yadav
Ranch Hand
Joined: Jul 30, 2008
Posts: 162
|
|
Hey Wait ! Wait !! Please look at the following code you can find your solution. I think it will solve your problem Thanking You - Kuldeep [ November 11, 2008: Message edited by: Kuldeep Yadav ]
|
 |
vinoth subramaniam
Ranch Hand
Joined: Jul 05, 2008
Posts: 47
|
|
QUOTE] Hey Wait ! Wait !! Please look at the following code you can find your solution. code: -------------------------------------------------------------------------------- List list = session.createQuery( "from CONTACT C") .setFetchMode( "persons ", FetchMode.SELECT ) .list(); Iterator iter = list.iterator(); while (iter.hasNext()) { CONTACT con = (CONTACT) iter.next(); List personlist=con.getPersons(); for (Iterator iterator = personlist.iterator(); iterator.hasNext() { Person personobj= (Person) iterator.next(); System.out.println(con.getID()); System.out.println(con.getFIRSTNAME()); System.out.println(personobj.getStreet()); } } -------------------------------------------------------------------------------- I think it will solve your problem Thanking You - Kuldeep
Sorry boss, can you please point out the error... sorry i cant catch that one...
|
 |
vinoth subramaniam
Ranch Hand
Joined: Jul 05, 2008
Posts: 47
|
|
Hi all, I resolved my problem, i used criteria API instead of the HQL. The problem is with the result set. And i resloved it by the following way list = session.createCriteria(PLAN.class).setFetchMode("suspenses",FetchMode.JOIN). setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY).list(); Thanks for your time... :
|
 |
 |
|
|
subject: Problem in hibernate join result
|
|
|