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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:33:15+00:00 2026-05-25T11:33:15+00:00

Is this possible to map a SQL Native query (instead of a table) with

  • 0

Is this possible to map a SQL Native query (instead of a table) with an Entity without annotations (using XML configuration)??

I know that i can make a View in the database and map this view as a workaround to this, but I try to avoid this solution because the Schema is automatically generated from the Entities model, and I would have to create the view manually afterwards.

I know also that with annotations there exist something like @SqlResultSetMapping, but I am not allowed to use annotations.

  • 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-25T11:33:15+00:00Added an answer on May 25, 2026 at 11:33 am

    For mapping legacy tables on an entity using Hibernate you could use a DAO method like this one:

    public List<Audit> getAudits(Integer branchId, Integer locationId, Date fromDate, Date toDate, int first, int count, String sortProperty, boolean ascending) {
    
        // columns renamed to match sort properties and hibernate mapping
        StringBuilder query = new StringBuilder(
            "SELECT AUD_Number AS number,"
            + " AUD_Number_REL AS relationNumber,"
            + " AUD_Name_REL AS relationName,"
            + " AUD_Date AS date,"
            + " FROM audit WHERE 1");
            if (branchId!= null) {
                query.append(String.format(" AND AUD_Number_BRN = %s", branchId));
            }
            if (locationId!= null) {
                query.append(String.format(" AND AUD_Nummer_LOC = %s", locationId));
            }
            if (fromDate != null) {
                query.append(String.format(" AND AUD_Date >= %s", DateConverter.dateToSql(fromDate)));
            }
            if (toDate != null) {
                query.append(String.format(" AND AUD_Date <= %s", DateConverter.dateToSql(toDate)));
            }
            query.append(String.format(" ORDER BY %s %s", sortProperty, ascending ? "ASC" : "DESC"));
            query.append(String.format(" LIMIT %s, %s", first, count));
            return (List<Audit>) getSession().createSQLQuery(query.toString()).addEntity(Audit.class).list();
    }
    

    Meanwhile in mappings.hbm.xml:

    <class name="Audit">
        <id name="number" type="integer" />
        <property name="relationNumber" type="integer" />
        <property name="relationName" type="string" />
        <property name="date" type="datetime" />
    </class>
    etc...
    

    Omitting spring context for brevity.

    Does this help?

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

Sidebar

Related Questions

I need to create native SQL query with couple of unions and subqueries. It'll
I am using Hibernate to map with MySQL I have an entity class in
Is this possible? I want to have the To:, Body, and an Attachment all
Is this possible? I am looking forward to a tutorial which explains the steps
Is this possible? I had troubles with SVN clients not being able to access
Is this possible? I can't find it anywhere.
Is this possible? Or would I miss something? (Fixtures,..?) Because: When I use autotest
Is this possible? I am creating a single base factory function to drive factories
Is this possible? I've followed the instructions from here ( http://www.jetbrains.net/confluence/display/TCD4/Setting+up+an+External+Database#SettingupanExternalDatabase-MicrosoftSQLServer2005 ) but I
Is this possible: myList = [] myList[12] = 'a' myList[22] = 'b' myList[32] =

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.