I have used this statements to populate jcombobox from MySql database table using Hibernate
String SQL_QUERY ="from Item items";
org.hibernate.Query query = session.createQuery(SQL_QUERY);
for(Iterator it=query.iterate();it.hasNext();){
Object[] row = (Object[]) it.next();
jcbItemCode.addItem(row[0]);
}
Here Item is my class name & items is my database table name. But NetBeans gives an error like follows & jcombo box does not populate.
INFO: schema update complete
Hibernate: select item0_.itemid as col_0_0_ from items item0_
eretailer.Item$$EnhancerByCGLIB$$99948c46 cannot be cast to [Ljava.lang.Object;
How can I correct this problem. I have searched but couldn’t find suitable answer.
I have used this method before…
String SQL_QUERY = "Select items.iid,items.idiscription,items.iprice from Item items";
org.hibernate.Query query = session.createQuery(SQL_QUERY);
for(Iterator it=query.iterate();it.hasNext();){
Object[] row = (Object[]) it.next();
jcbItemCode.addItem(row[0]);
}
This is working perfectly.
Perhaps Net beans does not allow that way. I want to know what exactly this is. Hope your help.
Thanks!!!
The query
from Item items, as indicated by the error message, doesn’t returnObject[]instances. It returnsIteminstances.If you want your combo box to contain Item instances, just use