Handling large numbers in reports with nHibernate queries

For general questions and discussions specific to the AbleCommerce GOLD ASP.Net shopping cart software.
Post Reply
User avatar
AbleMods
Master Yoda
Master Yoda
Posts: 5170
Joined: Wed Sep 26, 2007 5:47 am
Location: Fort Myers, Florida USA

Handling large numbers in reports with nHibernate queries

Post by AbleMods » Wed Mar 26, 2014 10:44 am

I recently ran into a situation with a client where the report query simply wasn't designed to handle larger installs. This is something to consider when you specifically total the Quantity field. So I thought I would share the issue and the solution with the community.

In a larger store, it's quite easy for a nHibernate SUM command to exceed the max value for Int16 values. Since most report queries don't specifically cast the quantity total, nHibernate is defaulting to Int16 which limits the value to 32,767. Any total that results in a larger number throws an exception.

For example, this is what happens in ReportDataSource.GetProductBreakdownSummary():
Server Error in '/' Application.

Value was either too large or too small for an Int16.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.OverflowException: Value was either too large or too small for an Int16.

Source Error:


Line 1419: .SetResultTransformer(Transformers.AliasToBean(typeof(ProductBreakdownSummary)));
Line 1420:
Line 1421: IList<ProductBreakdownSummary> summaryList = criteria.List<ProductBreakdownSummary>();
Line 1422: IProductRepository productRepository = AbleContext.Resolve<IProductRepository>();
Line 1423:
The solution is to cast the total column into something larger. So this:

Code: Select all

.Add(Projections.Sum("OI.Quantity"), "Quantity")
becomes this:

Code: Select all

.Add(Projections.Sum(Projections.Cast(NHibernateUtil.Int32, Projections.Property("OI.Quantity"))), "Quantity")
It's a pretty easy fix but you have to remember it when you're first designing your reports. So far I only ever have to do this when I'm doing a SUM on the Quantity column.
Joe Payne
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com

User avatar
Katie
AbleCommerce Admin
AbleCommerce Admin
Posts: 2651
Joined: Tue Dec 02, 2003 1:54 am
Contact:

Re: Handling large numbers in reports with nHibernate queries

Post by Katie » Thu Mar 27, 2014 7:29 am

Thanks for providing this information Joe. We'll have this fixed in our next release.
Thank you for choosing AbleCommerce!

http://help.ablecommerce.com - product support
http://wiki.ablecommerce.com - developer support

User avatar
ForumsAdmin
AbleCommerce Moderator
AbleCommerce Moderator
Posts: 399
Joined: Wed Mar 13, 2013 7:19 am

Re: Handling large numbers in reports with nHibernate queries

Post by ForumsAdmin » Sat Mar 29, 2014 2:08 am

Joe I guess you fixed this in R5 ... Because in R6 we already fixed most of these issues using the same technique described above.

Post Reply