The first thing that strikes me is that the SQL query isn't returning all of the properties declared in the entity mapping (I don't see "Id" or "Account")
/Pete
From: nhu...@googlegroups.com
[mailto:nhu...@googlegroups.com] On Behalf Of Fan Yang
Sent: 05 March 2013 13:07
To: nhu...@googlegroups.com
Subject: [nhusers] System.IndexOutOfRangeException: Unable to find
specified column in result set
I'm getting the follow error, can anyone kindly help?
System.IndexOutOfRangeException: Unable to find specified column in result set
at Oracle.DataAccess.Client.OracleDataReader.GetOrdinal(String
name)
at NHibernate.Type.NullableType.NullSafeGet(IDataReader rs, String
name)
at NHibernate.Type.NullableType.NullSafeGet(IDataReader rs,
String[] names, ISessionImplementor session, Object owner)
at NHibernate.Loader.Loader.GetKeyFromResultSet(Int32 i, ILoadable
persister, Object id, IDataReader rs, ISessionImplementor session)
at NHibernate.Loader.Loader.GetRowFromResultSet(IDataReader
resultSet, ISessionImplementor session, QueryParameters queryParameters,
LockMode[] lockModeArray, EntityKey optionalObjectKey, IList hydratedObjects,
EntityKey[] keys, Boolean returnProxies)
at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session,
QueryParameters queryParameters, Boolean returnProxies)
at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor
session, QueryParameters queryParameters, Boolean returnProxies)
at NHibernate.Loader.Loader.DoList(ISessionImplementor session,
QueryParameters queryParameters)
Here is my mapping:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="BusinessDataTransfer"
namespace="BusinessDataTransfer" >
<class name="GetPLCAndNSPLC">
<id name="Id" column="Id"
type="guid" >
<generator class="guid.comb" />
</id>
<property name="AccountId"
column="SERVICEPOINTID"/>
<property name="Type"
column="ATTRTYPE" />
<property name="Value"
column="ATTRVAL" />
<property name="StartTime"
column="STARTTIME" />
<property name="StopTime"
column="STOPTIME" />
<many-to-one name="Account"
class="Account" column="UIDACCOUNT"/>
</class>
<sql-query name="Query_PLC_NSPLC">
<query-param name="AccountUid"
type="int"/>
<return class="GetPLCAndNSPLC"
alias="rec" />
select s.SERVICEPOINTID as {rec.AccountId}, mt.ATTRTYPE as
{rec.Type}, sm.ATTRVAL as {rec.Value}, sm.STARTTIME as {rec.StartTime},
sm.STOPTIME as {rec.StopTime}
from table1 s
inner join table2 sm on sm.uidservicepoint =
s.uidservicepoint
inner join table3 mt on mt.uidmarketattrtype =
sm.uidmarketattrtype
inner join Account a on s.Servicepointid = a.accountid
where a.uidaccount = :AccountUid and mt.ATTRTYPE like
'%REQUIREMENT%'
order by SERVICEPOINTID, ATTRTYPE
</sql-query>
</hibernate-mapping>
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to nhusers+u...@googlegroups.com.
To post to this group, send email to nhu...@googlegroups.com.
Visit this group at http://groups.google.com/group/nhusers?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
!DSPAM:1,5135f1471871901010113!
The <sql-query /> declares that it returns a GetPLCAndNSPLC entity.
The <class name="GetPLCAndNSPLC" /> declares 7 columns
The <sql-query /> returns 5 columns
You have an IndexOutOfRangeException : Unable to find specified column in result set
What happens if you return all 7 columns in the <sql-query />? E.g.
select ….. , s.Id as {rec.Id}, s.UIDACCOUNT as {rec.Account}
/Pete
From: nhu...@googlegroups.com
[mailto:nhu...@googlegroups.com] On Behalf Of Fan Yang
Sent: 05 March 2013 13:47
To: nhu...@googlegroups.com
Subject: [nhusers] Re: System.IndexOutOfRangeException: Unable to find
specified column in result set
Account is just a relational mapping. I tried: <id
name="AccountId" column="SERVICEPOINTID"><generator
class="native"/></id> and removed the relationship
<many-to-one />. Profiler shows SQL executed with
correct parameter, but the parent class wasn't set the SetOfPLCAndNSPLC.
Here is my Account.hbm.xml:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="BusinessDataTransfer"
namespace="BusinessDataTransfer" >
<class name="Account" table="ACCOUNT">
<id name="AccountUid"
column="UIDACCOUNT">
<generator class="native"/>
</id>
<property name="AccountId"
column="ACCOUNTID" />
<set name="SetOfPLCAndNSPLC"
inverse="true">
<key column="SERVICEPOINTID" />
<one-to-many class="GetPLCAndNSPLC"/>
<loader query-ref="Query_PLC_NSPLC"
/>
</set>
</class>
</hibernate-mapping>
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to nhusers+u...@googlegroups.com.
To post to this group, send email to nhu...@googlegroups.com.
Visit this group at http://groups.google.com/group/nhusers?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
!DSPAM:1,5135f7d51872125023446!
By the sound of it, there are a few different issues here which probably have different causes.
Firstly - the original problem you posted; I'm 99% certain that amending the query as suggested will resolve this issue.
Secondly - Account.SetOfPLCAndNSPLC is null. Without context and C# code, it's hard to guess what you're referring to but I'm going to assume that you have code such as:
IQuery getPlcAndNsplcQuery = …;
GetPLCAndNSPLC something = getPlcAndNsplcQuery.UniqueResult();
something.Account.SetOfPLCAndNSPLC == null; // true
*if* that's the case then I'd suspect the Account's constructor which I'd expect to initialise the collection, e.g.
class Account {
public virutal ICollection<GetPLCAndNSPLC> SetOfPLCAndNSPLC { get; protected set; }
public Account() {
this.SetOfPLCAndNSPLC = new Iesi.Collections.Generic.HashedSet<GetPLCAndNSPLC>();
}
Thirdly - there's a NullReferenceException somewhere, which as Oskar's said is quite impossible to analyze without the stack trace and some context.
At the risk of causing offence, which I don't wish to do and apologise if it's taken in that way, I suspect that you're trying to use some relatively 'advanced' features in the form of the sql-query and loader without having a firm grasp of the NHibernate basics. Although people will be happy to try and help, you may not get as much benefit as you should unless you've built strong foundations for the knowledge. Because of that, I'd suggest that you build a simple domain model using the 'basic' features and use that develop your understanding of collection behaviours, constructors and mappings. There are several things about the mappings and your posts that give me this suspicion, in particular the mixing of the Account class (domain entity?) with the GetPLCAndNSPLC class (DTO?); the fact that Account.SetOfPLCAndNSPLC is null; and a general lack of coherency about the mappings). You may well find that you don't even _need_ to use the SQL query…
/Pete
From: nhu...@googlegroups.com
[mailto:nhu...@googlegroups.com] On Behalf Of Fan Yang
Sent: 05 March 2013 17:50
To: nhu...@googlegroups.com
Subject: Re: [nhusers] Re: System.IndexOutOfRangeException: Unable to
find specified column in result set
Pete,
I followed your suggestion to add rec.Account, from profiler I can see the SQL
statement ran, but the Account.SetOfPLCAndNSPLC is null. I
added: NHibernateUtil.Initialize(acct.SetOfPLCAndNSPLC) and it doesn't
work. The ISet<GetPLCAndNSPLC> SetOfPLCAndNSPLC is decorated with
public virtual. I'm so confused. I set break
point at the setter in Account.cs, which is not triggered.
wbr>5135f7d51872125023446!
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to nhusers+u...@googlegroups.com.
To post to this group, send email to nhu...@googlegroups.com.
Visit this group at http://groups.google.com/group/nhusers?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
!DSPAM:1,513631bf1872635720902!