I wite a application, my application is insert, delete, update good, but i can't query by "select * from ...", it error here
Code:
Query quey = session.createQuery("select * from Person");
this is my class Main
Code:
import java.util.Iterator;
import java.util.List;
import org.hibernate.*;
import org.hibernate.cfg.Configuration;
public class Main {
public static void main(String[] args) {
SessionFactory sessions = new Configuration().configure().buildSessionFactory();
Session session = sessions.openSession();
Transaction tx = null;
try {
tx = session.beginTransaction();
//insert, update, delete is good here
Query query = session.createQuery("select * from PERSON");
List list = query.list();
Iterator iter = list.iterator();
int i = 0;
while ( iter.hasNext() ){
i++;
Person p = (Person)iter.next();
System.out.println("Person " + i + " " + p.getName());
}
tx.commit();
tx = null;
} catch ( HibernateException e ) {
if ( tx != null ) tx.rollback();
e.printStackTrace();
} finally {
session.close();
}
}
}
It is insert, update, delete good but can't execute query !! Help me plz, Thank a lot of