Hi,
Hibernate version: 1.0.2
Name and version of the database you are using: MsSQL 2000
Using BLOBs with SQLClient fails if NDataReader gets used.
If the table containing the BLOB get's load --> no problem. The problem ocurrs when you load a child of this table.
I was able to reproduce it with northwind Database. If you try to load an Order_Details it will try to load the Employee Photo --> exception.
The exception is obvious since the buffer passed is null and the code is trying to use that null value to copy the content of the blob..
I've modified the source but first thought was wiser to post it here to see if somebody else got the same problem and found alternative solutions..
Modified method:
public long GetBytes( int i, long fieldOffset, byte[ ] buffer, int bufferOffset, int length )
{
if( cachedByteArray == null || cachedColIndex != i )
{
cachedColIndex = i;
cachedByteArray = ( byte[ ] ) GetValue( i );
}
long remainingLength = cachedByteArray.Length - fieldOffset;
if( remainingLength < length )
{
length = ( int ) remainingLength;
}
// STA 17-3-2006 : Modified
if (buffer == null) return remainingLength;
Array.Copy(cachedByteArray, fieldOffset, buffer, bufferOffset, length);
return length;
}
Full stack trace of any exception that occurs:
Type:System.ArgumentNullException
Message:Value cannot be null. Parameter name: dest
Source:mscorlib
ParamName:dest
TargetSite:Void Copy(System.Array, Int32, System.Array, Int32, Int32, Boolean)
HelpLink:null
StackTrace:
at System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length, Boolean reliable)
at System.Array.Copy(Array sourceArray, Int64 sourceIndex, Array destinationArray, Int64 destinationIndex, Int64 length)
at NHibernate.Driver.NDataReader.GetBytes(Int32 i, Int64 fieldOffset, Byte[] buffer, Int32 bufferOffset, Int32 length) in C:\Program Files\NHibernate\src\NHibernate\Driver\NDataReader.cs:line 263
at NHibernate.Driver.NHybridDataReader.GetBytes(Int32 i, Int64 fieldOffset, Byte[] buffer, Int32 bufferoffset, Int32 length) in C:\Program Files\NHibernate\src\NHibernate\Driver\NHybridDataReader.cs:line 246
at NHibernate.Type.BinaryType.Get(IDataReader rs, Int32 index) in C:\Program Files\NHibernate\src\NHibernate\Type\BinaryType.cs:line 58
at NHibernate.Type.NullableType.NullSafeGet(IDataReader rs, String name) in C:\Program Files\NHibernate\src\NHibernate\Type\NullableType.cs:line 264
at NHibernate.Type.NullableType.NullSafeGet(IDataReader rs, String[] names, ISessionImplementor session, Object owner) in C:\Program Files\NHibernate\src\NHibernate\Type\NullableType.cs:line 206
at NHibernate.Type.AbstractType.Hydrate(IDataReader rs, String[] names, ISessionImplementor session, Object owner) in C:\Program Files\NHibernate\src\NHibernate\Type\AbstractType.cs:line 127
at NHibernate.Loader.Loader.Hydrate(IDataReader rs, Object id, Object obj, ILoadable persister, ISessionImplementor session, String[][] suffixedPropertyColumns) in C:\Program Files\NHibernate\src\NHibernate\Loader\Loader.cs:line 824
at NHibernate.Loader.Loader.LoadFromResultSet(IDataReader rs, Int32 i, Object obj, Key key, String suffix, LockMode lockMode, ILoadable rootPersister, ISessionImplementor session) in C:\Program Files\NHibernate\src\NHibernate\Loader\Loader.cs:line 751
at NHibernate.Loader.Loader.InstanceNotYetLoaded(IDataReader dr, Int32 i, ILoadable persister, String suffix, Key key, LockMode lockMode, Key optionalObjectKey, Object optionalObject, IList hydratedObjects, ISessionImplementor session) in C:\Program Files\NHibernate\src\NHibernate\Loader\Loader.cs:line 709
at NHibernate.Loader.Loader.GetRow(IDataReader rs, ILoadable[] persisters, String[] suffixes, Key[] keys, Object optionalObject, Key optionalObjectKey, LockMode[] lockModes, IList hydratedObjects, ISessionImplementor session) in C:\Program Files\NHibernate\src\NHibernate\Loader\Loader.cs:line 631
at NHibernate.Loader.Loader.GetRowFromResultSet(IDataReader resultSet, ISessionImplementor session, QueryParameters queryParameters, IList hydratedObjects, Object optionalObject, Object optionalId, Key[] keys, Boolean returnProxies) in C:\Program Files\NHibernate\src\NHibernate\Loader\Loader.cs:line 253
at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Object optionalObject, Object optionalId, Object[] optionalCollectionKeys, Boolean returnProxies) in C:\Program Files\NHibernate\src\NHibernate\Loader\Loader.cs:line 348
at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Object optionalObject, Object optionalId, Object[] optionalCollectionKeys, Boolean returnProxies) in C:\Program Files\NHibernate\src\NHibernate\Loader\Loader.cs:line 168
at NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters) in C:\Program Files\NHibernate\src\NHibernate\Loader\Loader.cs:line 1311
at NHibernate.Loader.Loader.List(ISessionImplementor session, QueryParameters queryParameters, ISet querySpaces, IType[] resultTypes) in C:\Program Files\NHibernate\src\NHibernate\Loader\Loader.cs:line 1299
at NHibernate.Loader.CriteriaLoader.List(ISessionImplementor session) in C:\Program Files\NHibernate\src\NHibernate\Loader\CriteriaLoader.cs:line 116
at NHibernate.Impl.SessionImpl.Find(CriteriaImpl criteria) in C:\Program Files\NHibernate\src\NHibernate\Impl\SessionImpl.cs:line 4763
The generated SQL (show_sql=true):
Console Output
NHibernate :SELECT top 100 this.OrderID as OrderID8_, this.ProductID as ProductID8_, this.Discount as Discount8_, this.UnitPrice as UnitPrice8_, this.Quantity as Quantity8_, orders1_.OrderID as OrderID0_, orders1_.ShippedDate as ShippedD4_0_, orders1_.ShipPostalCode as ShipPos10_0_, orders1_.RequiredDate as Required3_0_, orders1_.ShipCountry as ShipCou11_0_, orders1_.OrderDate as OrderDate0_, orders1_.ShipAddress as ShipAddr7_0_, orders1_.ShipRegion as ShipRegion0_, orders1_.ShipName as ShipName0_, orders1_.EmployeeID as EmployeeID0_, orders1_.ShipCity as ShipCity0_, orders1_.Freight as Freight0_, orders1_.CustomerID as CustomerID0_, orders1_.ShipVia as ShipVia0_, employees2_.EmployeeID as EmployeeID1_, employees2_.PostalCode as PostalCode1_, employees2_.Photo as Photo1_, employees2_.TitleOfCourtesy as TitleOfC5_1_, employees2_.Address as Address1_, employees2_.ReportsTo as ReportsTo1_, employees2_.HireDate as HireDate1_, employees2_.LastName as LastName1_, employees2_.Region as Region1_, employees2_.HomePhone as HomePhone1_, employees2_.Extension as Extension1_, employees2_.PhotoPath as PhotoPath1_, employees2_.Title as Title1_, employees2_.Notes as Notes1_, employees2_.FirstName as FirstName1_, employees2_.BirthDate as BirthDate1_, employees2_.Country as Country1_, employees2_.City as City1_, employees3_.EmployeeID as EmployeeID2_, employees3_.PostalCode as PostalCode2_, employees3_.Photo as Photo2_, employees3_.TitleOfCourtesy as TitleOfC5_2_, employees3_.Address as Address2_, employees3_.ReportsTo as ReportsTo2_, employees3_.HireDate as HireDate2_, employees3_.LastName as LastName2_, employees3_.Region as Region2_, employees3_.HomePhone as HomePhone2_, employees3_.Extension as Extension2_, employees3_.PhotoPath as PhotoPath2_, employees3_.Title as Title2_, employees3_.Notes as Notes2_, employees3_.FirstName as FirstName2_, employees3_.BirthDate as BirthDate2_, employees3_.Country as Country2_, employees3_.City as City2_, customers4_.CustomerID as CustomerID3_, customers4_.Country as Country3_, customers4_.City as City3_, customers4_.Phone as Phone3_, customers4_.Region as Region3_, customers4_.ContactTitle as ContactT4_3_, customers4_.Address as Address3_, customers4_.Fax as Fax3_, customers4_.PostalCode as PostalCode3_, customers4_.ContactName as ContactN3_3_, customers4_.CompanyName as CompanyN2_3_, shippers5_.ShipperID as ShipperID4_, shippers5_.Phone as Phone4_, shippers5_.CompanyName as CompanyN2_4_, products6_.ProductID as ProductID5_, products6_.CategoryID as CategoryID5_, products6_.UnitsOnOrder as UnitsOnO6_5_, products6_.ProductName as ProductN2_5_, products6_.ReorderLevel as ReorderL7_5_, products6_.Discontinued as Disconti8_5_, products6_.QuantityPerUnit as Quantity3_5_, products6_.SupplierID as SupplierID5_, products6_.UnitPrice as UnitPrice5_, products6_.UnitsInStock as UnitsInS5_5_, categories7_.CategoryID as CategoryID6_, categories7_.CategoryName as Category2_6_, categories7_.Picture as Picture6_, categories7_.Description as Descript3_6_, suppliers8_.SupplierID as SupplierID7_, suppliers8_.Country as Country7_, suppliers8_.City as City7_, suppliers8_.Phone as Phone7_, suppliers8_.Region as Region7_, suppliers8_.ContactTitle as ContactT4_7_, suppliers8_.HomePage as HomePage7_, suppliers8_.Address as Address7_, suppliers8_.Fax as Fax7_, suppliers8_.PostalCode as PostalCode7_, suppliers8_.ContactName as ContactN3_7_, suppliers8_.CompanyName as CompanyN2_7_ FROM [dbo].[Order Details] this left outer join [dbo].[Orders] orders1_ on this.OrderID=orders1_.OrderID left outer join [dbo].[Employees] employees2_ on orders1_.EmployeeID=employees2_.EmployeeID left outer join [dbo].[Employees] employees3_ on employees2_.ReportsTo=employees3_.EmployeeID left outer join [dbo].[Customers] customers4_ on orders1_.CustomerID=customers4_.CustomerID left outer join [dbo].[Shippers] shippers5_ on orders1_.ShipVia=shippers5_.ShipperID left outer join [dbo].[Products] products6_ on this.ProductID=products6_.ProductID left outer join [dbo].[Categories] categories7_ on products6_.CategoryID=categories7_.CategoryID left outer join [dbo].[Suppliers] suppliers8_ on products6_.SupplierID=suppliers8_.SupplierID WHERE 1=1
NHibernate :select orders0_.OrderID as OrderID, orders0_.ShippedDate as ShippedD4_, orders0_.ShipPostalCode as ShipPos10_, orders0_.RequiredDate as Required3_, orders0_.ShipCountry as ShipCou11_, orders0_.OrderDate as OrderDate, orders0_.ShipAddress as ShipAddr7_, orders0_.ShipRegion as ShipRegion, orders0_.ShipName as ShipName, orders0_.EmployeeID as EmployeeID, orders0_.ShipCity as ShipCity, orders0_.Freight as Freight, orders0_.CustomerID as CustomerID, orders0_.ShipVia as ShipVia from [dbo].[Orders] orders0_ where (orders0_.OrderID=@p0)
NHibernate :select products0_.ProductID as ProductID, products0_.CategoryID as CategoryID, products0_.UnitsOnOrder as UnitsOnO6_, products0_.ProductName as ProductN2_, products0_.ReorderLevel as ReorderL7_, products0_.Discontinued as Disconti8_, products0_.QuantityPerUnit as Quantity3_, products0_.SupplierID as SupplierID, products0_.UnitPrice as UnitPrice, products0_.UnitsInStock as UnitsInS5_ from [dbo].[Products] products0_ where (products0_.ProductID=@p0)
|