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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:23:49+00:00 2026-05-26T15:23:49+00:00

I have a really ugly legacy database system that I need to integrate with.

  • 0

I have a really ugly legacy database system that I need to integrate with. Essentially I’m doing some read only reporting on the system, and I don’t want to set up a thousand entities representing each of the tables that I’m working on. Instead, I’d like to just define an Entity for each of the report-types that I generate (essentially a union of a bunch of columns from different tables), and then let hibernate map from the nasty (many joined, many unioned) sql query to a list of such entities.

The question is: can I create an entity that doesn’t have an underlying table, and use a sql statement to populate a list of said entities?

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-26T15:23:50+00:00Added an answer on May 26, 2026 at 3:23 pm

    We do that sort of thing all the time – and here is how we do it:

    1. Define a simple bean-like object to represent each row of output in your report:

      public class CityStateRevenueReport {
      
          private String mId;
          private String mState;
          private String mCity;
          private Double mRevenue;
      
          public String getId() { return mId; }
          public void setId(String i) { mId = i; }
          public String getState() { return mState; }
          public void setState(String s) { mState = s; }
          public String getCity() { return mCity; }
          public void setCity(String c) { mCity = c; }
          public Double getReveneue() { return mRevenue; }
          public void setRevneue(Double d) { mRevenue = d; }
      }
      
    2. Define a hibernate mapping file, CityStateRevneueReport.hbm.xml:

      <?xml version="1.0" ?>
      <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd&quot;>
      <hibernate-mapping>
          <class entity-name="CityStateRevenueReport">
              <id name="Id" type="java.lang.String" column="report_id">
                  <generator class="sequence" />
              </id>
              <property name="city" type="string" column="city" />
              <property name="state" type="string" column="state" />
              <property name="revenue" type="double" column="revenue" />
          </class>
          <sql-query name="runReport">
              <![CDATA[ 
              SELECT {r.*} FROM 
                  (select some_id_value as report_id, 
                          state_abbreviation as state, 
                          city_name as city, 
                          dollar_amount as revenue 
                     from -- tables, joins, other SQL insanity 
                   ) r
              ]]>
              <return alias="r" class="CityStateRevenueReport" />
          </sql-query>
      </hibernate-mapping>
      
    3. Then run the query and populate instances:

      public List<CityStateRevenueReport> runReport() {
      
          List<CityStateRevenueReport> reports = 
                                   new ArrayList<CityStateRevenueReport>();
          List<HashMap> maps = session.getNamedQuery("runReport").list()
          for ( HashMap map : results ) {
              CityStateRevenueReport report = new CityStateRevenueReport();
              report.setState(map.get("state"));
              report.setCity(map.get("city"));
              report.setRevenue(Double.parseDouble(map.get("revenue"));
              reports.add(report);
          }
          return reports;
      }
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database table full of some really ugly and messy data. In
I have some really complicated legacy code I've been working on that crashes when
We’ve found that the unit tests we’ve written for our C#/C++ code have really
I have a really big database (running on PostgreSQL) containing a lot of tables
The problem I have is that I need to do about 40+ conversions to
We are going to develop a new system over a legacy database(using .NET C#).There
I have to work with a legacy system based on SQL Anywhere 5, db
I have a working solution right now, but it seems really ugly for something
I have some C# code that walks XML schemata using the Xml.Schema classes from
I have some EDI messages (X12, HL7, etc ...) stored in an Oracle database.

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.