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.  [ 2 posts ] 
Author Message
 Post subject: How can I get an enumerator on all the stored objects?
PostPosted: Tue Nov 27, 2007 8:55 am 
Newbie

Joined: Tue Nov 27, 2007 8:31 am
Posts: 5
NHibernate version:1.2.1.4000

I am trying to query my data base to get an enumerator on all the objects in it. I am simply passing a query in the form of:

Code:
IQuery query = session.CreateQuery("from System.Object");


This query returns an empty enumerator when I call
Code:
query.Enumerable();
(I am not showing all the code)

However if I specifically write the type of the objects I want to take (I have one object type in my data base

Code:
IQuery query = session.CreateQuery("from TestAssembly.Person");


query.Enumerable() - now returns an enumerator containing the objects from the data base. In my scenario I do not know the objects type in advance.
I want the query to return an enumerator that enumerates on all the objects.

Am I supposed to enable something in the config or the mapping of person so it will support inheritance in queries?

Thanks
Eitan


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 27, 2007 1:24 pm 
Expert
Expert

Joined: Fri May 13, 2005 11:13 am
Posts: 292
Location: Rochester, NY
That should work (see http://www.hibernate.org/hib_docs/nhibe ... lymorphism). My guess is that List() would work (loading a large collection in one shot), but that Enumerable() isn't smart enough to set up new cursors when the end of each table in a polymorphic query is reached. So it just balks. If so, this should be fixed or documented.

In the meantime, if you need to use IEnumerable, you'll probably have to do some "thinking for it". I would suggest taking a look at the metadata in the Configuration object. You can find Type objects for all the mapped <class>es (plus a whole lot more, if you want to) there, then iterate over those.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.