-->
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.  [ 5 posts ] 
Author Message
 Post subject: SetResultTransformer bug?
PostPosted: Thu Dec 14, 2006 2:05 pm 
Beginner
Beginner

Joined: Thu Jun 01, 2006 11:27 am
Posts: 28
I'm trying to do the following:


IQuery query = session.CreateSQLQuery("SELECT TITLE FROM TABLE")
.SetResultTransformer(Transformers.AliasToBean(typeof(ReportData))) ;

IList<ReportData> result = query.List<ReportData>();



NHibernate throw "Return types of SQL query were not specified"; what's wrong?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 14, 2006 2:22 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Well, return types of the SQL query were not specified :) You have to use AddScalar/AddEntity to specify what that query is supposed to return.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 14, 2006 2:27 pm 
Beginner
Beginner

Joined: Thu Jun 01, 2006 11:27 am
Posts: 28
But documentation say that

13.1.5. Returning non-managed entities

It is possible to apply an IResultTransformer to native sql queries. Allowing it to e.g. return non-managed entities.

sess.CreateSQLQuery("SELECT NAME, BIRTHDATE FROM CATS")
.SetResultTransformer(Transformers.AliasToBean(typeof(CatDTO)))

This query specified:
• the SQL query string
• a result transformer
The above query will return a list of CatDTO which has been instantiated and injected the values of NAME and

BIRTHNAME into its corresponding properties or fields.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 14, 2006 2:55 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Hmm, I will have to fix the documentation then.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 03, 2007 12:28 pm 
Newbie

Joined: Tue Apr 03, 2007 12:04 pm
Posts: 1
Hello,

i had the same problem with Returning non-managed entities as swtechno.

But the following example works now fine for me:
Code:
IQuery query = session.CreateSQLQuery("SELECT DISTINCT TABLE_SCHEMA FROM INFORMATION_SCHEMA.COLUMNS WHERE (TABLE_SCHEMA<>'information_schema' AND TABLE_SCHEMA<>'mysql')").AddScalar("TABLE_SCHEMA", NHibernateUtil.String).SetResultTransformer(Transformers.AliasToBean(typeof(Schema)));


Schema is a small class with one property.


My Problem now is that i can not aliased the database columnsname "TABLE_SCHEMA" to my property "Name", because now the propertyname is the same as the databasecolumn. this is not nice.


Is there a way and how can i do it?


Thanks Axel


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