For Retrieving the records from Employee and Address tables using one-to-many relationship

package test;

import java.util.Iterator;
import java.util.Set;

import org.hibernate.Session;

import session.HibernateSessionFactory;

import com.mapping.Address;
import com.mapping.Emp;

public class Test {
       public static void main(String[] args) {
       Session session=HibernateSessionFactory.getSession();
             
       Emp e=new Emp();
       session.load(e,1);
       System.out.println(e.getName());
       System.out.println(e.getSalary());
      
       Set s=e.getAddresses();
      
       Iterator ite= s.iterator();
       while(ite.hasNext()){
             
              Address add=(Address)ite.next();
             
              System.out.println(add.getVillage());
              System.out.println(add.getCity());
              System.out.println(add.getState());
             
       }
       }
}


Output:

Printed here

0 comments:

Post a Comment