Using NHibernate and MS Sql Server and VB in VS 2008.
I have a query that returns the right number of records but they are all the first record in the set. Records 2,3 do not get loaded.
I have show sql turned on and when I cut and paste that query into Microsoft SQL Managment Studio in a query window it gives the correct results.
The mapping:
Code:
<?xml version="1.0"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="true">
<class name="<assembly>.DBWrappers.DB_Association, <assembly>" lazy="false" table="Association">
<id name="User_ID" type="integer" column="User_ID">
<generator class="native" />
</id>
<property name="Account_ID" type="integer" column="Account_ID"/>
<property name="Supervisor_ID" type="integer" column="Supervisor_ID"/>
</class>
</hibernate-mapping>
The class:
Code:
Imports NHibernate
Imports NHibernate.Cfg
Imports log4net
Imports System.Configuration
Imports Iesi.Collections
Namespace DBWrappers
Public Class DB_Association
'------------------------------------------------------------------------------------------------
'
' DataBase Wrapper class for Table Association using the nhibernate framework
'
' AutoGenerated, Author: J.Putnam Date: 12/11/2009 3:16:58 PM
'
'------------------------------------------------------------------------------------------------
'---Table column variables
Private _User_ID As Integer
Private _Account_ID As Integer
Private _Supervisor_ID As Integer
'------------------------------------------------------------------------------------------------
'---------Get/Set for field: User_ID
'------------------------------------------------------------------------------------------------
Public Overridable Property User_ID() As Integer
Get
Return _User_ID
End Get
Set(ByVal Value As Integer)
_User_ID = Value
End Set
End Property
'------------------------------------------------------------------------------------------------
'---------Get/Set for field: Account_ID
'------------------------------------------------------------------------------------------------
Public Overridable Property Account_ID() As Integer
Get
Return _Account_ID
End Get
Set(ByVal Value As Integer)
_Account_ID = Value
End Set
End Property
'------------------------------------------------------------------------------------------------
'---------Get/Set for field: Supervisor_ID
'------------------------------------------------------------------------------------------------
Public Overridable Property Supervisor_ID() As Integer
Get
Return _Supervisor_ID
End Get
Set(ByVal Value As Integer)
_Supervisor_ID = Value
End Set
End Property
End Class
End Namespace
The code that is running the query:
Code:
Dim session2 As ISession = hibClass.OpenSession()
Dim queryBack2 As IQuery = session2.CreateQuery("select a from DB_Association a where a.User_ID = 10")
Dim assocAcctList As IList = queryBack2.List() '---get users associated to this account
For Each assocRec2 As DB_Association In assocAcctList
System.Console.WriteLine(" --acct: " & assocRec2.Account_ID & " user: " & assocRec2.User_ID & " supId: " & assocRec2.Supervisor_ID)
Next
session2.Close()
The reulsts of the running code:
NHibernate: select db_associa0_.User_ID as User1_94_, db_associa0_.Account_ID as Account2_94_, db_associa0_.Supervisor_ID as Supervisor3_94_ from Association db_associa0_ where db_associa0_.User_ID=10
--acct: 2 user: 10 supId: 9 These lines should have different account numbers!!!!
--acct: 2 user: 10 supId: 9
--acct: 2 user: 10 supId: 9
The results from running the sql directly:
Code:
user acct# sup#
10 2 9 You can see the query returns different account numbers!!!
10 3 9
10 4 9
I don't think this should be possible and may be a bug in nhibernate.
Anyone know how this could happen, or what to do to isolate the issue further?