-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Beginner Question. <very basic>
PostPosted: Mon Sep 21, 2009 11:15 am 
Newbie

Joined: Mon Sep 21, 2009 7:50 am
Posts: 2
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 Documents

Quote:
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



Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.