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 8474565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:39:40+00:00 2026-06-10T17:39:40+00:00

HQL query against a PostgreSQL database: var checkLines = _Session.CreateQuery( @select lines from FinancialStatement

  • 0

HQL query against a PostgreSQL database:

var checkLines = _Session.CreateQuery(
    @"select lines from FinancialStatement statement
        inner join fetch statement.FinancialStatementLines lines
    where statement.FinancialStatementId = :statementId
        and lines.TransactionType = :transactionType
        and length(lines.CheckNumber) > 0")
    .SetParameter("statementId", statement.FinancialStatementId)
    .SetParameter("transactionType", TransactionTypes.Debit)
    .List<FinancialStatementLine>();

The query looks OK to me, but I am a newbie at HQL. Can someone tell me what I’m doing wrong? I’m assuming the problem is with the HQL, please let me know if you think I need to look elsewhere.

THE PLOT THICKENS

Upon examining the query created by the above HQL, I discover it looks like this:

select 
    financials1_.LineId as LineId14_, 
    financials1_.FinancialStatementId as Financia2_14_, 
    financials1_.APPaymentID as APPaymen3_14_, 
    financials1_.EffectiveDate as Effectiv4_14_, 
    financials1_.Amount as Amount14_, 
    financials1_.TransactionType as Transact6_14_, 
    financials1_.CheckNumber as CheckNum7_14_, 
    financials1_.Description as Descript8_14_, 
    financials1_.VendorDescription as VendorDe9_14_, 
    financials1_.FinancialStatementId as Financia2_, 
    financials1_.LineId as LineId 
from 
    FinancialStatements financials0_ 
where 
    financials0_.FinancialStatementId=:p0 
    and financials1_.TransactionType=:p1 
    and length(financials1_.CheckNumber)>0

…now, WTF? The select clause aliases don’t exist in the from clause, which explains the error, but not, of course, why the error exists.

How can I work around this?

  • 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-06-10T17:39:41+00:00Added an answer on June 10, 2026 at 5:39 pm

    So here’s the deal: apparently when using HQL, to generate the right query, you need to have the object type you are trying to get as the first part of the query, for example:

    var paymentLines = _Session.CreateQuery(
        @"select lines from FinancialStatementLine lines
            inner join fetch lines.Statement statement
        where statement.FinancialStatementId = :statementId
            and lines.TransactionType = :transactionType")
        .SetParameter("statementId", statement.FinancialStatementId)
        .SetParameter("transactionType", TransactionTypes.Debit)
        .List<FinancialStatementLine>();
    

    This works, where the other query doesn’t. In SQL, the order of the joins doesn’t matter so much; in HQL, it seems quite important.

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

Sidebar

Related Questions

When I write a HQL query Query q = session.createQuery(SELECT cat from Cat as
I have simple HQL query: var list = OpenSession() .CreateQuery(SELECT MAX(p.price) as max_price, COUNT(p.id)
I have a following HQL query: SELECT s.id FROM stack s WHERE s.category is
Consider the following query in HQL: SELECT m.id, (SELECT (COUNT(*) > 0) FROM SubqueryTable...)
I have this hql query, which works perfect: select m from Media m join
I use NHibernate 1 and have a HQL query SELECT mo FROM MyObject mo
I use the fallowing HQL-Query with NHibernate: from Contact a where a.Id in (select
I need to replicate the following working HQL query using criteria API. session.CreateQuery( select
Here is my HQL query: select p, pp, pp.Mrn, pp.Name from PatientProfile pp left
I have a problem with the following HQL query: select sum(MYTABLE.COUNTER) from ( select

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.