This project is read-only.

HQL query causes Stackoverflow

Topics: Writing modules
Aug 24, 2013 at 1:03 PM

I'm implementing a module. I'm going to change the impelmentation because I realized I've overnormalized things (hoping it would be more scalable) and the overhead of joins has proven it was wrong, or I did it wrong.

Anyway, I would like to know if I'm coding something wrong to get a stack overflow exception from SQL CE library.

Here is my piece of code that gets it:
        public IEnumerable<WagerPart> GetWagers(IEnumerable<int> competitionIds, bool summaryOnly = true)
            if (summaryOnly)
                return _services.ContentManager.HqlQuery<WagerPart>()
                    .Where(x => x.ContentPartRecord<WagerPartRecord>(), z => z.And(lhs => lhs.In("Competition.Id", competitionIds.ToArray()), rhs => rhs.In("WagerType.Code",_summaryWagerTypes))).List();

            return _services.ContentManager.Query<WagerPart, WagerPartRecord>().Where(w => competitionIds.ToList().Contains(w.Competition.Id)).List();

Here is the relevant model classes:
    public class WagerTypePartRecord : ContentPartRecord
        public virtual string Name { get; set; }
        public virtual string Code { get; set; }

    public class WagerPartRecord : ContentPartRecord
        public virtual CompetitionPartRecord Competition { get; set; }
        public virtual WagerTypePartRecord WagerType { get; set; }
        public virtual double Ratio { get; set; }
Here is what VS points to when stackoverflow occurs (Orchard.ContentManagement.DefaultContentManager):
        private IEnumerable<ContentItemVersionRecord> GetManyImplementation(QueryHints hints, Action<ICriteria, ICriteria> predicate) {
            var session = _sessionLocator.Value.For(typeof (ContentItemRecord));
            var contentItemVersionCriteria = session.CreateCriteria(typeof (ContentItemVersionRecord));
.......... [deleted]


            return contentItemVersionCriteria.List<ContentItemVersionRecord>();
Orchard version is 1.7.

So, I know for a fact that the first query (with HQL) should fetch fewer records from the database, since it adds another filter by WagerType.Code. However, it first gets the Ids of published versions, and then uses id's in another query to get the actual records.

If I call the method with summaryOnly argument set to false, the second query is executed. It is a regular content manager query, gets the complete list without extra filter, and it works.

I suspected that the reason the first query fails is too many records for SQL CE to handle in an SQL IN clause, but I don't understand why the second works for even more records.

So please tell me if I'm doing something wrong (as I know near to nothing about hibernate or HQL) or if it's a known bug, or by design or a limitation of HQL queries.