-->
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.  [ 6 posts ] 
Author Message
 Post subject: Query with multiple classes - how?
PostPosted: Fri Oct 24, 2003 3:06 pm 
Newbie

Joined: Fri Oct 24, 2003 2:59 pm
Posts: 6
Location: Swalmen, The Netherlands
(I've send this message to the development list too, it doesn't belong there. Mea Culpa.)

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:
Code:
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.






Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 24, 2003 3:32 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
A collection of Object[], where index 0 is a Cat and index 1 is an
Integer.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 24, 2003 4:04 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
...Hibern8IDE is a great thing for such explorations ;)


(just so ya'know ;)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 24, 2003 4:25 pm 
Newbie

Joined: Mon Oct 20, 2003 3:03 pm
Posts: 13
Jython (http://www.jython.org) is a JVM scripting language that can be run interactively (i.e., gives immediate feedback) that I find invaluable for testing HQL:


>>> import net.sf.hibernate as hibernate

>>> sf = hibernate.cfg.Configuration().configure("/my.hibernate.cfg.xml").buildSessionFactory()

>>> sess = sf.openSession()

>>> rs=sess.find("select x from x in class BasePlanTerritory")

>>> rs
[com.revenuetech.mpi.beans.BasePlanTerritory@14b3a9e[terrId=1], com.revenuetech.
mpi.beans.BasePlanTerritory@b7b6ef[terrId=4], com.revenuetech.mpi.beans.BasePlan
Territory@17e4c97[terrId=5]]

>>> [x.name for x in rs]
['Corporate', 'Filters', 'Ride Control']


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 24, 2003 4:49 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Dude, Hibern8ide now has a beanshell for doing this kind of stuff. Try it, its great.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 25, 2003 5:56 am 
Newbie

Joined: Fri Oct 24, 2003 2:59 pm
Posts: 6
Location: Swalmen, The Netherlands
[quote="max"]...Hibern8IDE is a great thing for such explorations ;)


(just so ya'know ;)[/quote]

I've looked at the site and it certainly looks promising! I'll try it out. Thanks for the link.


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

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.