[Hibernate] Query with multiple classes - how?

2003-10-24 Thread Maurice le Rutte
The Hibernate documentation states in chapter 9 (Hibernate Query Language)

"Multiple classes may appear, resulting in a cartesian product or "cross" 
join.

from Formula, Parameter

from Formula as form, Parameter as param"

A bit later something similar:
"select cat, count( elements(cat.kittens) ) from eg.Cat cat group by cat"
It is not clear to me what the result of such a query would be. What type 
would be the contents of the objects contained by the collection returned 
by the query's list() or iterate() methods.

For example let's assume I've executed the "cat" query:

session = ...
query = session.getNamedQuery("Cat_and_kitten_count");
iterator = query.iterate();

while (iterator.hasNext()) {
Object element;
element = iterator.next();
// what type is element?
// How to get the cat and the kitten count?
}
At the moment I don't have an infrastructure to try this easily on and this 
problem is nagging my mind...

Maurice.







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


Re: [Hibernate] Query with multiple classes - how?

2003-10-24 Thread Christian Bauer
On 24 Oct (20:49), Maurice le Rutte wrote:

> "select cat, count( elements(cat.kittens) ) from eg.Cat cat group by cat"
> 
> It is not clear to me what the result of such a query would be. What type 
> would be the contents of the objects contained by the collection returned 
> by the query's list() or iterate() methods.

A collection of Object[], where index 0 is a Cat and index 1 is an
Integer.

-- 
Christian Bauer
[EMAIL PROTECTED]


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


[Hibernate] RE: Hibernate Query Object

2003-10-24 Thread Chandrasekhar Ambadipudi
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