File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Object Relational Mapping and the fly likes Help in Hibernate accessing objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Help in Hibernate accessing objects" Watch "Help in Hibernate accessing objects" New topic

Help in Hibernate accessing objects

Rajeswari Gopal

Joined: Apr 14, 2005
Posts: 26
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.

String SQL_QUERY1="SELECT person.firstName, person.lastName, user.firstName, user.lastName "+
"FROM Person person,"+
"UserModel user " +

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.get(i) instanceof List);

Person ppp =(Person)joinlist.get(i); System.out.println("person table details");
UserModel um =(UserModel)joinlist.get(i);
System.out.println("users table details");
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

String SQL_QUERY1="SELECT person.firstName, person.lastName, user.firstName, user.lastName "+
"FROM Person person,"+
"UserModel user " +

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.

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
I agree. Here's the link:
subject: Help in Hibernate accessing objects
It's not a secret anymore!