Hi
I am trying to do simple query (get all names) on the table using Hibernate. For that I write a simple business logic function getAllName() as follow:
Code:
public ArrayList<String> getAllAgencyName() {
ArrayList<String> agencyNames = new ArrayList<String>();
try{
Transaction tx = session.beginTransaction();
Query q = session.createQuery("FROM Agency");
agencyNames = (ArrayList<String>) q.list();
for(String a: agencyNames){
System.out.println("Agency Name: " + a);
}
}catch(Exception e){
log.error("Error in getting all agency name: " + e);
}
return agencyNames;
}
Now when I run the application it give me an error saying
Code:
java.lang.ClassCastException: mypkg.pojo.Agency cannot be cast to java.lang.String
while entering the for loop.
What am I doing wrong?