Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:3.1
Name and version of the database you are using:MySql 5.0
Hi guys,
I got 3 classes below:
Code:
public abstract class Animal{
private Long id;
private String name;
}
public class Dog extends Animal{
private boolean bark;
private String typeOfDogFood;
}
public class Cat extends Animal{
private boolean miau;
private String typeOfCatFood;
}
if I do a query like below:
Code:
public List findAnimal(Long id) {
return getHibernateTemplate().find(
"from Animal ani where ani.id = ?",
new Object[] { id});
}
and return a List, how do I know which class, Dog or Cat should I cast to when iterating over the list:
Code:
for (Iterator it=clist.iterator(); it.hasNext(); ) {
Object element = (Dog)it.next();
Object element = (Cat)it.next();
}
if I cast the wrong class, system will throw severe exception ! Pls help, Thanks !