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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T06:25:31+00:00 2026-06-16T06:25:31+00:00

I am having a trouble with executing an HQL query like this: select new

  • 0

I am having a trouble with executing an HQL query like this:

select new myPackage.view.CoverDocumentReportView(Re.code AS fulCd,
Re.creditPrice AS crtprc,
Re.debitPrice  AS dbtprc,
(Re.debitPrice - Re.debitPrice) AS redbtprc,
(Re.creditPrice- Re.creditPrice) AS recrtprc,
(Re.debitPrice-Re.creditPrice)   AS rem) 
from 
(select  fullCode as code, 
     sum(creditPrice) as creditPrice ,
     sum(debitPrice)  as debitPrice   
from    DocumentMaster DM,
     DocumentAccount   DA,
     Tree              T ,
     AccountTree       AT, 
     DocumentDetailed  DD 
where DM.id =  DA.documentMaster  and  
      DA.accountTree =  T.id      and   
      DA.accountTree =  AT.id     and   
      DD.documentAccount =  DA.id 
group by  DA.accountTree ) As Re

1)
If I execute this like:

SQLQuery crit = (SQLQuery) session
            .createSQLQuery(sql).setResultTransformer(Transformers.aliasToBean(CoverDocumentReportView.class));
ArrayList<CoverDocumentReportView> li =  (ArrayList<CoverDocumentReportView>) crit.list();

ERROR 2012-12-22 14:16:19,838 [http-8080-1] org.hibernate.util.JDBCExceptionReporter : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘.datx.web.accounting.view.CoverDocumentReportView(Re.code AS fulCd,
Re.creditP’ at line 1


2)
If I execute it with this:

Query query = session.createQuery(sql).setResultTransformer(Transformers.aliasToBean(CoverDocumentReportView.class));
ArrayList<CoverDocumentReportView> li =  (ArrayList<CoverDocumentReportView>)query.list();

The error will be:

ERROR 2012-12-22 14:51:46,709 [http-8080-1] org.hibernate.hql.ast.ErrorCounter : line 1:224: unexpected token: (
ERROR 2012-12-22 14:51:46,709 [http-8080-1] org.hibernate.hql.ast.ErrorCounter : line 1:308: unexpected token: sum

What is the problem?

  • 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-16T06:25:32+00:00Added an answer on June 16, 2026 at 6:25 am

    SQL and HQL are two different languages.

    HQL doesn’t support subqueries in from clauses, so this query can’t be an HQL query.

    And SQL doesn’t know about Java objects, and doesn’t have any new() function allowing to create them, so the query is not a valid SQL query either.

    Make it a valid SQL query, execute it using createSQLQuery(), then iterate through the results and create instances of your objects from the returned rows. Or use a result transformer as you’re doing, which will do that for you. the result transformer will use the aliases you assigned to the returned columns of the SQL query to create beans for you. You don’t need any new CoverDocumentReportView() in the query to make that work. Read the javadoc for details.

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

Sidebar

Related Questions

I'm having trouble executing a Doctrine DQL Query. This is the error it gives
I'm having some trouble executing a nested sql query. It works fine when i
I am having trouble executing at command via php. When I start this job,
I'm having trouble executing a stored proc... I've got C# code that tries to
I'm new to Capistrano and having trouble debugging an error. Searching suggests this error
I'm having trouble executing an UPDATE-query with fmdb. It locks the application without any
Using Advantage Database Server 8.1 I am having trouble executing a successful query. I
I'm having some trouble executing a dynamic query inside my SP, and I thought
I'm having some trouble executing the slideDown() function in the code below. I'm using
Having trouble with each function... Will try to explain by example... In my code,

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.