Hi all,
In the following code am fetching a list object which has two different object values i.e Person,UserModel. can you please help me to retrive the values in the list.
i am getting list of values if am using one object person or Usermodel but the following code is not working..
am getting classcastException..
Please reply ASAP.
CODE
-------
String SQL_QUERY1="SELECT person.firstName, person.lastName, user.firstName, user.lastName "+
"FROM Person person,"+
"UserModel user " +
"WHERE person.id=user.userId";
ArrayList joinlist=(ArrayList)sessionFactory.getCurrentSession().createQuery(SQL_QUERY1).list();
for(int i=0;i<joinlist.size();i++)
{
System.out.println(joinlist.get(i) instanceof Person);
System.out.println(joinlist.get(i) instanceof UserModel);
System.out.println(joinlist.getClass());
System.out.println(joinlist.get(i) instanceof List);
Person ppp =(Person)joinlist.get(i); System.out.println("person table details");
System.out.println("--------------------");
System.out.println("firstname----->"+ppp.getFirstName());
System.out.println("lastname------>"+ppp.getLastName());
UserModel um =(UserModel)joinlist.get(i);
System.out.println("users table details");
System.out.println("--------------------");
System.out.println("firstname----->"+um.getFirstName());
System.out.println("lastname------>"+um.getLastName());
System.out.println("age------>"+um.getAge());
}
In the following code am fetching a list object which has two different object values i.e Person,UserModel. can you please help me to retrive the values in the list.
i am getting list of values if am using one object person or Usermodel but the following code is not working..
am getting classcastException..
Please reply ASAP.
CODE
-------
String SQL_QUERY1="SELECT person.firstName, person.lastName, user.firstName, user.lastName "+
"FROM Person person,"+
"UserModel user " +
"WHERE person.id=user.userId";
ArrayList joinlist=(ArrayList)sessionFactory.getCurrentSession().createQuery(SQL_QUERY1).list();
for(int i=0;i<joinlist.size();i++)
{
System.out.println(joinlist.get(i) instanceof Person);
System.out.println(joinlist.get(i) instanceof UserModel);
System.out.println(joinlist.getClass());
System.out.println(joinlist.get(i) instanceof List);
Person ppp =(Person)joinlist.get(i); System.out.println("person table details");
System.out.println("--------------------");
System.out.println("firstname----->"+ppp.getFirstName());
System.out.println("lastname------>"+ppp.getLastName());
UserModel um =(UserModel)joinlist.get(i);
System.out.println("users table details");
System.out.println("--------------------");
System.out.println("firstname----->"+um.getFirstName());
System.out.println("lastname------>"+um.getLastName());
System.out.println("age------>"+um.getAge());
}