This is my hibernate code, i have used the HQL statement
String SQL_QUERY ="FROM addProject "; , instead of writing it as String SQL_QUERY ="FROM
* addProject "; , i have to do that because, i got an exception. I need to know the reason, why You have to specify the HQL statement like that..
Question 2. Now i wont to count the number of records that is stored in the MYSQL Database, how do i write the HQL Statement for this.
I am an absolute beginner to Hibernate, so can some one please help me. i am lost ....
Code:
import org.hibernate.Session;
import org.hibernate.*;
import org.hibernate.cfg.*;
import java.util.Iterator;
import java.util.*;
public class SelectRecords {
public static void main(String[] args) {
Session session = null;
try{
// This step will read hibernate.cfg.xml and prepare hibernate for use
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session =sessionFactory.openSession();
//Create Select Clause HQL
String SQL_QUERY ="FROM addProject a ";
Query query = session.createQuery(SQL_QUERY);
for(Iterator it=query.iterate();it.hasNext();){
addProject row = (addProject) it.next();
System.out.println( row.getPath());
//break;
}
session.close();
}catch(Exception e){
System.out.println(e.getMessage());
}finally{
session.flush();
session.close();
}
}
}
QUESTION 3.. This is my output... and i need to store the output on to an array. But, there are some other lines that are getting displayed before the output
addproject0_.path as path0_0_ from addproject addproject0_ where addproject0_.id=? What is this ??
and how do i get rid of this, and get a list of the real output which is
the location is C:\Documents and Settings\Shami\My DocumentsQuote:
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Hibernate: select addproject0_.id as col_0_0_ from addproject addproject0_
Hibernate: select addproject0_.id as id0_, addproject0_.projname as projname0_0_, addproject0_.path as path0_0_ from addproject addproject0_ where addproject0_.id=?
the location is C:\Documents and Settings\Shami\My Documents
Hibernate: select addproject0_.id as id0_, addproject0_.projname as projname0_0_, addproject0_.path as path0_0_ from addproject addproject0_ where addproject0_.id=?
the location is C:\DLinks
Hibernate: select addproject0_.id as id0_, addproject0_.projname as projname0_0_, addproject0_.path as path0_0_ from addproject addproject0_ where addproject0_.id=?
the location is C:\Docu