-->
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.  [ 7 posts ] 
Author Message
 Post subject: Generics and ICriteria
PostPosted: Thu Apr 20, 2006 4:03 am 
Newbie

Joined: Thu Apr 13, 2006 9:26 am
Posts: 9
Hello,

I have checked out and compiled the SVN version of NH to get generics support. I modified my classes and my mapping files to use ISet<> and everything looks fine.

I have one concern however: when I want to retrieve data from the DB I currently use the ICriteria interface like this:

IList items = m_session.CreateCriteria(typeof(Person)).List();

The List() method always returns a IList that I then have to convert to an IList<Person> (or ISet<Person>) which is very ineffective. Is there another way to do this or is Generic support not currently implemented everywhere in NH (I know I am playing with a development version...)?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 20, 2006 4:38 am 
Newbie

Joined: Thu Apr 13, 2006 9:26 am
Posts: 9
BTW, I have checked ISession.Find and this also returns an IList...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 20, 2006 6:45 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
I'll add Find<T> and List<T> methods which will return IList<T> objects (actually List<T>). But you will still have to specify the type twice: CreateCriteria (typeof (SomeType)).List<SomeType>();

Will this be good enough?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 20, 2006 8:35 am 
Newbie

Joined: Thu Apr 13, 2006 9:26 am
Posts: 9
Hello,

thanks for the answer. At last I know there is not something existing that I did not find. Honestly I am brand new to NH so I do not think I have enough knowledge to give my opinion on this but can't Criteria be a generic class therefore the syntax could be:

ICriteria<T> crit = m_session.CreateCriteria<T>().List();

Thanks,
nbon


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 20, 2006 9:11 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Criteria queries will have projections (i.e. selecting individual fields, counting, summing, etc.) eventually, so ICriteria<T>.List() won't necessarily return a list of T's.

Besides, I feel that generifying the query classes will only complicate things because every function that would need to take an argument of that class would need to be generic as well.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 20, 2006 1:48 pm 
Beginner
Beginner

Joined: Sat Dec 10, 2005 6:22 pm
Posts: 28
Location: Chicago, IL
When will Critiea queries support projections, I was going to add a feature request to jira about this. Does Hibernate 3 offer projection support?


Top
 Profile  
 
 Post subject: Projections exist in Hibernate 3.1
PostPosted: Fri Apr 21, 2006 10:24 am 
Newbie

Joined: Wed Jan 25, 2006 3:42 pm
Posts: 5
Location: Tallahassee, FL
I'm not sure how feature complete projections are in Hibernate 3.1 but it exists.

I have had a huge need for projections for quite some time now as I often need to project a flattened view of queries. A particular case is when I adapt the result set into a different model - a dBase table for example. I do this for a GIS framework I'm developing which uses ESRI shape files and dBase files to store spatial data. So a typical process for me is to QBE in NHibernate, then adapt that result set into a GIS layer (ShapeFile + dBase table). For now however, it's been very tough as I have to traverse the List and reflectively pluck out the properties (and nested types) to stuff it into a dBase table. I need to be able to do this genericly as I'm building my own framework that will work will multiple data models at once. So I can't do things like foreach(Entity e in results) { /*...*/} - it must ne agnostic to the result set.

Serg, as if you don't already have enough on your plate, but I wondered if you could throw a bone on a neat way to do this? Making use of an adapter pattern, I wanna be able to form a projection as efficiently as possible. Of course, once projections is ported over to NHibernate, this would greatly simplify things.

As it stands now, I'm actually doing a bit of a hack to get it to work, using DLinq's projection capability. So my sequence is: [1] load and build the configuration, [2] retrieve the session, [3] QBE, [4] project the result set using DLinq taking advantage of C# 3.0 anonymous types, [4] adapt into dBase file. There is nasty overhead with this because I have to first convert the IList into a List<T>, thereby forcing a complete fetch (needed anyway to build the dBase file), finally to adapt it.

Serg or anyone, how would you go about this?

Thanks in advance,

Timex


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