I tried to convert the List I got from Hibernate to AdminPopulate type using the following code, and I got this error
Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to model.AdminPopulate
public class Test
{
public static void main(String[] args)
{
SubUser subUser=new SubUser();
List subUserList=subUser.getSubUserAll();
List<AdminPopulate> subUserListAdminPop=new ArrayList<AdminPopulate>();
for(Object p:subUserList)
{
subUserListAdminPop.add((AdminPopulate)p);
}
for(AdminPopulate p:subUserListAdminPop)
{
System.out.println("first ="+p.getFirstName());
}
}
}
....and this is the getSubUserAll() method
public List getSubUserAll()
{
Session session=null;
List resultsList=null;
try
{
CreateHibernateSession hbSession=new CreateHibernateSession();
session=hbSession.getHBSession();
String sql = "SELECT SubUser.FirstName,\n" +
"SubUser.LastName,\n" +
"SubUser.UserName,\n" +
"SubUserType.Name\n" +
"FROM SubUser\n" +
"INNER JOIN SubUserType ON SubUser.idSubUserType = SubUserType.idSubUserType\n" +
"WHERE SubUserType.idSubUserType != 0";
Query query = session.createSQLQuery(sql);
resultsList = query.list();
return resultsList;
}
catch(Exception ex)
{
ex.printStackTrace();
}
finally
{
session.close();
}
return resultsList;
}
Object
tomodel.AdminPopulate
which isn't an acceptable cast. – Sufian Feb 10 at 10:14