Actually I could solve this problem...I havent looked enough in to API
dcoumentation for the method query.setParameter :-)

        Bind a value to a JDBC-style query parameter. 
                Parameters:
                        position - the position of the parameter in the
query string, numbered from 0.
                        val - the possibly-null parameter value
                        type - the Hibernate type

Thanks
Chandra

-----Original Message-----
From: Chandrasekhar Ambadipudi 
Sent: Thursday, October 23, 2003 1:07 AM
To: 'Gavin King'; Chandrasekhar Ambadipudi
Cc: '[EMAIL PROTECTED]'
Subject: Hibernate Query Object



 Hi,
 Iam trying to use pagenation by Query object and its setMaxRows,
setFirstRow. I have a block of code like this

         String oql = FIND_BY_TEAM_OQL;
            Session sess = null;
        try {

             sess = basePersistence.getSessionFactory().openSession();
            uery query = sess.createQuery(oql);
            query.setMaxResults(10);
            query.setFirstResult(firstRowId);
            query.setParameter(1, teamId, Hibernate.STRING);
            List students  = query.list();
            return students;
        } catch (HibernateException e) {
            throw new PersistenceException(e.getMessage(), e);
        }finally {
            basePersistence.close(sess);
  }
     my  OQL looks like this 

        private static final String FIND_BY_TEAM_OQL
        = "Select sp.student FROM StudentProgram sp WHERE "
        + " sp.team.teamId = ?  "
        + "ORDER by sp.student.lastName, sp.student.firstName";

        IAm getting this following nullpointer exception inside hibernate
code any idea ?

Hibernate: select * from ( select row_.*, rownum rownum_ from ( select
student1_.IRN as IRN, student1_.version as version, student1_.FIRST_NAME as
FIRST_NAME, student1_.LAST_NAME as LAST_NAME, student1_.EMAIL_ADDRESS as
EMAIL_AD7_, student1_.ACADEMIC_STATUS as ACADEMIC8_, student1_.RISK_CODE as
RISK_CODE, student1_.SD_COURSE_ID as SD_COUR10_, student1_.FOREIGN_STUDENT
as FOREIGN11_ from STUDENT_PROGRAM studentp0_, STUDENT student1_ where
studentp0_.STUDENT_IRN=student1_.IRN and ((studentp0_.TEAM_ID=? )) order by
student1_.LAST_NAME , student1_.FIRST_NAME ) row_ where rownum <= ?) where
rownum_ > ?
java.lang.NullPointerException
        at
net.sf.hibernate.loader.Loader.prepareQueryStatement(Loader.java:494)
        at net.sf.hibernate.loader.Loader.doFind(Loader.java:136)
        at net.sf.hibernate.loader.Loader.find(Loader.java:620)
        at
net.sf.hibernate.hql.QueryTranslator.find(QueryTranslator.java:928)
        at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1343)
        at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:76)
        at
com.apollo.s3.hibernate.DBStudent.findByTeamPagenated(DBStudent.java:155)
        at com.apollo.s3.hibernate.DBStudentTest.main(DBStudentTest.java:57)


IAm sure my main oql query is fine as it works if I directly use
session.find, and the number of results are in the range of few hundreds and
Iam calling it with firstRowID 1 and maxRows is set to 30. Iam using
hibernate version 2.0.3, 27 August 2003.

Any input is greatly appreciated,
Thanks in advance,
Chadnra


-------------------------------------------------------
This SF.net email is sponsored by: The SF.net Donation Program.
Do you like what SourceForge.net is doing for the Open
Source Community?  Make a contribution, and help us add new
features and functionality. Click here: http://sourceforge.net/donate/
_______________________________________________
hibernate-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/hibernate-devel

Reply via email to