Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6692277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:50:58+00:00 2026-05-26T05:50:58+00:00

I have this Fluent NHibernate mapping: public LossMap() { Table(losses); Id(x => x.Id).Column(id); References(x

  • 0

I have this Fluent NHibernate mapping:

public LossMap()
{
    Table("losses");
    Id(x => x.Id).Column("id");
    References(x => x.Policy).Column("pol_id");
    HasMany(x => x.Statuses).KeyColumn("loss_id").Cascade.All().Inverse();
    HasMany(x => x.Reserves).KeyColumn("loss_id").Cascade.All().Inverse();
    HasMany(x => x.Payments).KeyColumn("loss_id").Cascade.All().Inverse();
}

public LossPaymentMap()
{
    Table("losspayments");
    Id(x => x.Id).Column("id");
    Map(x => x.Type).Column("type_id");
    References(x => x.Reserve).Column("reserve_id");
}

public LossReserveMap()
{
    Table("lossreserves");
    Id(x => x.Id).Column("id");
    Map(x => x.Type).Column("type_id");
    Map(x => x.Status).Column("status_id");
    References(x => x.ParentReserve).Column("parent_reserve_id");
}

public LossStatusMap()
{
    Table("lossstatuses");
    Id(x => x.Id).Column("id");
    Map(x => x.Status).Column("status_id");
    Map(x => x.ExpirationDate).Column("expirationdate");
    References(x => x.Loss).Column("loss_id");
}

To summarize:

  1. Loss has many Payments, Reserves and Statuses
  2. Payment has one Reserve

I am trying to fetch Losses and their payments and reserves (but not statuses) with the following constraints:

  1. Only fetch Losses which have at least one status with
    “status.Status not in (1,2,7)”.
  2. Only fetch Loss.Payments where “loss.Payment.Type = 2 and loss.Payment.Reserve.Status != 4)”
  3. Only fetch Loss.Reserves where Reserve.Status != 3

As I am trying to fetch 2 parallel relations, I have to use multiqueries or futures to avoid Cartesian product (right?), as explained here: http://ayende.com/blog/4367/eagerly-loading-entity-associations-efficiently-with-nhibernate

I came up with this query (in HQL):

int[] statuslist = new int[3] {1, 2, 7};

var losses =
session.CreateQuery(
    "from Loss l left join fetch l.Payments as payment join l.Statuses as status where l.Policy.Product.Id = :tid1 " + 
    "and status.Status not in ( :statuslist1) " +
    "and payment.Type = 2 and payment.Reserve.Status != 4")
    .SetParameter("tid1", productid)
    .SetParameterList("statuslist1", statuslist)
    .Future<Loss>();

session.CreateQuery(
    "from Loss l left join fetch l.Reserves as reserve join l.Statuses as status where l.Policy.Product.Id = :tid2 " +
    "and status.Status not in ( :statuslist2) " +
    "and reserve.Status != 3 ")
    .SetParameter("tid2", productid)
    .SetParameterList("statuslist2", statuslist)
    .Future<Loss>();

var list = losses.ToList();

However, when executing this query, I get an error: NHibernate.HibernateException: Failed to execute multi query[..SQL query]—> System.ArgumentException: The value “System.Object[]” is not of type “Entities.Loss” and cannot be used in this generic collection.

Any clues what am I doing wrong here ?

When I remove the status constraint, the query works:

var losses =
session.CreateQuery(
    "from Loss l left join fetch l.Payments as payment where l.Policy.Product.Id = :tid1 " + 
    "and payment.Type = 2 and payment.Reserve.Status != 4")
    .SetParameter("tid1", productid)
    .Future<Loss>();

session.CreateQuery(
    "from Loss l left join fetch l.Reserves as reserve where l.Policy.Product.Id = :tid2 " +
    "and reserve.Status != 3 ")
    .SetParameter("tid2", productid)
    .Future<Loss>();

However, the results are not what I want (I need that constraint).

Any advice ?

Oh, and using HQL is not a “must-be”, if this is possible using Linq or QueryOver, I’ve got not problem with that.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T05:50:59+00:00Added an answer on May 26, 2026 at 5:50 am

    You have a join but have not specified which object you want thus you’re actually getting back a tuple.

    You should specify which entities/properties you want in the select, eg:

    select l
    from Loss l left join fetch l.Payments as payment
    where l.Policy.Product.Id = :tid1
    and payment.Type = 2 and payment.Reserve.Status != 4
    

    You should also note that when using a join you can get multiple results for the same entity, if you only want unique entities you should use Transformers.DistinctRootEntity

    For IQuery/ICriteria: .SetResultTransformer(Transformers.DistinctRootEntity)
    For QueryOver: .TransformUsing(Transformers.DistinctRootEntity)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following entity and Fluent NHibernate mapping: public class Advertiser { public
How do I specify with fluent NHibernate mapping for a table that doesn't have
This is a Fluent NHibernate newbie question, so bear with me. I have a
I have this table structure and would like to map it using Fluent Hibernate
I'm using FluentNHibernate but NHibernate XML will do. Say I have this model public
I have implement testing app. which uses fluent nhibernate mapping to db object inside
What's the equivalent of <key column=Person_id/> in Fluent NHibernate?? <class xmlns=urn:nhibernate-mapping-2.2 mutable=true name=FluentTry.Person, FluentTry,
I have dictionary which I'm mapping using Fluent NHibernate. The dictionary has a complex
I have two classes from example using Fluent NHibernate mapping. Fluent NHibernate mapping is
I have a funny feeling this is just my understanding of nHibernate and Fluent

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.