Forums Register Login

Help in Hibernate accessing objects

+Pie Number of slices to send: Send
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());
}
+Pie Number of slices to send: Send
 


String SQL_QUERY1="SELECT person.firstName, person.lastName, user.firstName, user.lastName "+
"FROM Person person,"+
"UserModel user " +
"WHERE person.id=user.userId";


Your query asks for specific properties of the object. In HQL (your variable name is confusing, you should probably change it) if you do this the return type is an object array. If is it Person objects you are after, don't specify specific fields.
Seriously? That's what you're going with? I prefer this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 840 times.
Similar Threads
ID:8 SCJP Question of the day !!!
how the values added from two different browsers can be seen in either of the browsers?
Search using Hibernate criteria querry
Problem in displaying multiple search results
saxParser
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 19, 2024 04:00:26.