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

  • Home
  • SEARCH
  • 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 1097939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:30:21+00:00 2026-05-17T00:30:21+00:00

I am trying to run a SQL query in Hibernate. I am using its

  • 0

I am trying to run a SQL query in Hibernate. I am using its documentation.
Because of some unknown values i am trying to do inside the Source code.

See this below SQL-Query configuration. How to re-write it in source code itself!!
I tried this

personList = session.createSQLQuery("SELECT person.NAME, person.AGE, person.SEX, address.STREET, address.CITY, address.STATE, address.ZIP FROM person JOIN address WHERE person.ID = address.PERSON_ID").addEntity(Person.class).addEntity(Address.class).list();

What i am trying to do with the above query is, it should map person.ID & PERSON_ID. If it matches, then fetch the other columns in the ADDRESS[STREET, CITY, STATE, ZIP] table with the PERSON table columns[NAME, AGE, SEX].

In JDBC the columns of resultset, for the above query looks like

NAME, AGE, SEX, STREET, CITY, STATE, ZIP

But its not working it says, address columns in the query were not found. Is there any syntax error in my version of query!!

Query Declaration in mapping file;

<sql-query name="personsWith">
<return alias="person" class="eg.Person"/>
<return-join alias="address" property="person.mailingAddress"/>
SELECT person.NAME AS {person.name},
       person.AGE AS {person.age},
       person.SEX AS {person.sex},
       address.STREET AS {address.street},
       address.CITY AS {address.city},
       address.STATE AS {address.state},
       address.ZIP AS {address.zip}
FROM PERSON person
JOIN ADDRESS address
    ON person.ID = address.PERSON_ID
</sql-query>

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-17T00:30:22+00:00Added an answer on May 17, 2026 at 12:30 am

    Two posible causes for not finding the address columns:

    First, in SQL you have to write the name of the table, not the entity name.

    Second, your JOIN sentence could be invalid at SQL. There are a few ways to implement a join. I’ll take the direct approach (select from both table and stating the join at the where clause).

    Suposing that the person entity maps a table called “TABLE_PERSON“, and address maps table “TABLE_ADDRESS“, a valid query would look as follows:

    SELECT person.NAME, person.AGE, person.SEX, 
         address.STREET, address.CITY, address.STATE, address.ZIP 
    FROM TABLE_PERSON person, TABLE_ADDRESS address 
    WHERE person.ID = address.PERSON_ID
    

    One more point. Checking the hibernate documentation, I have found this example:

    List cats = sess.createSQLQuery("select {cat.*}, {kitten.*} from cats cat, cats kitten 
    where kitten.mother = cat.id").
         setResultSetMapping("catAndKitten").list();
    

    So, maybe the problem is not at the query itself, but on the resultSet Mapping you are using, and the way to reference the fields.

    Let’s suppose this mapping (from the Hibernate doc):

    <resultset name="personAddress">
        <return alias="person" class="eg.Person"/>
        <return-join alias="address" property="person.mailingAddress"/>
    </resultset>
    

    Then, as the exaple states, your query should define the columns between curly brackets ({}), and using the alias you have defined at the mapping:

    personList = session.createSQLQuery(
                 "SELECT {person.NAME}, {person.AGE}, {person.SEX}, "+
                "{address.STREET}, {address.CITY}, {address.STATE}, {address.ZIP} "+
                "FROM TABLE_PERSON person, TABLE_ADDRESS address "
                "WHERE person.ID = address.PERSON_ID"
            ).setResultSetMapping("personAddress")
             .list();
    

    Please, tell me if any of this examples works.

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

Sidebar

Ask A Question

Stats

  • Questions 545k
  • Answers 545k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • added an answer Well, start off by thinking of which bits of data… May 17, 2026 at 9:17 am
  • added an answer For this task it is a good idea to use… May 17, 2026 at 9:15 am
  • added an answer This is exactly how the Skyhook database (built into many… May 17, 2026 at 9:15 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I'm trying to run a LINQ to SQL query that returns a result in
With PHP I'm trying to run a SQL query and select normal columns as
I'm trying to run SQuirreL SQL. I've downloaded it and installed it, but when
SQL Server 2000 on Windows Server 2003. I am trying to run a backup,
What I'm trying to do is run the same SQL select on many Oracle
I'm trying to run some queries to get rid of XSS in our database
I'm trying to run a process and do stuff with its input, output and
I get a Antlr.Runtime.NoViableAltException thrown when trying to run the following query in NHibernate.
I am using JPA with hibernate and trying to connect to the a datasource
The following SQL I am trying to run is returning sql_string of SELECT id

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.