My scenario: NHibernate v1.0.2.0 | SQL Server 2000 | VB.NET 2005.
My problem:
I am trying to obtain all articles of the table, but it gives the following exception:
"No row with the given identifier exists: 249, of class: Article".
ID 249 don't exist in the articles table and I do not understand because it tries to bring this ID.
From where obtains this ID?
Try different consultations and in all I such obtain results with values that are not either in the table.
My map file:
************************************************************************************************
<class name="Article" table="Articles">
<id name="_id" column="ID" unsaved-value="0" access="field">
<generator class="identity" />
</id>
<many-to-one name="_supplier" column="SupplierID" update="true" access="field" />
<property name="_supplierPrice" column="SupplierPrice" access="field"/>
<property name="_articletype" column="ArticleType" access="field"/>
<property name="_code" column="Code" access="field"/>
<property name="_name" column="Name" access="field"/>
<property name="_unit" column="Unit" access="field"/>
<property name="_image" column="Image" access="field" type="BinaryBlob"/>
<property name="_specs" column="Specs" access="field"/>
<property name="_isComponent" column="IsComponent" access="field"/>
<property name="_active" column="Active" access="field"/>
<bag name="_components" cascade="all" access="field" inverse="true" lazy="false">
<key column="ArticleID" />
<one-to-many class="ArticleComponent" />
</bag>
</class>
<class name="ArticleComponent" dynamic-update="true" table="ArticlesComponents">
<id name="_id" column="ID" unsaved-value="0" access="field">
<generator class="identity" />
</id>
<many-to-one name="_article" cascade="none" column="ArticleID" access="field" />
<many-to-one name="_component" cascade="none" column="ComponentID" access="field" />
<property name="_quantity" access="field" column="Quantity" />
<property name="_unit" access="field" column="UnitID" />
</class>
<class name="Supplier" table="Suppliers">
<id name="_id" column="ID" unsaved-value="0" access="field">
<generator class="identity" />
</id>
<property name="_code" column="Code" access="field"/>
<property name="_name" column="Name" access="field"/>
<property name="_contact" column="Contact" access="field"/>
<property name="_address" column="Address" access="field"/>
<property name="_telephone" column="Telephone" access="field"/>
<property name="_eMail" column="EMail" access="field"/>
<property name="_webSite" column="Website" access="field"/>
<property name="_comments" column="comments" access="field"/>
<property name="_myDiscount" column="MyDiscount" access="field"/>
<property name="_active" column="Active" access="field"/>
</class>
************************************************************************************************
My code:
Public Function GetActiveArticles() As IList
Dim session As ISession = Nothing
Try
session = _nhFactory.OpenSession
Return session.CreateCriteria(GetType(Article)). _
Add(Expression.Expression.Eq("_active", True)). _
AddOrder(Expression.Order.Asc("_name")).List
Catch ex As Exception
Throw New ApplicationException("Could not get articles.", ex)
Finally
If Not session Is Nothing Then _
session.Close()
End Try
End Function
Thank's in advance!!
|