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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:44:17+00:00 2026-05-27T17:44:17+00:00

I had performed query using Hibernate that refers to single table with where clause.

  • 0

I had performed query using Hibernate that refers to single table with where clause.

I am selecting following query in sql:

SELECT URN.ID,
  URN.USERNAME,
  (SELECT NAME FROM CITY WHERE ID=URN.CITY_ID
  ) AS CITY ,
  (SELECT NAME FROM STATE WHERE ID=URN.STATE_ID)  AS STATE,
  (SELECT NAME FROM COUNTRY WHERE ID = URN.COUNTRY_ID) AS COUNTRY
FROM USERREGISTRATION_NEW URN

URN.CITY_ID, URN.STATE_ID,URN.COUNTRY_ID contains numeric values.

City, State, Country name are retrieved from respective table on passing numeric id.

So, how can I write this query in Hibernate?

Also, I don’t understand the Many-to-One,etc tutorials?

I had taken Reference from Vaannila

  • 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-27T17:44:18+00:00Added an answer on May 27, 2026 at 5:44 pm

    This query can be translated literally to HQL. Just change table names into entity class names, and column names into entity property names, and you’ll have your HQL query.

    But this query should be written with joins. In SQL, it would be

    select urn.id, urn.username, city.name as city, state.name as state, country.name as country
    from USERREGISTRATION_NEW urn
    inner join city on urn.city_id = city.id
    inner join state on urn.state_id = state.id
    inner join country on urn.country_id = country.id
    

    And, using Hibernate, you would have a ManyToOne association between Urn and City, another one betwen Urn and State, and another one between Urn and Country. The HQL would then be:

    select urn.id, urn.userName, cityEntity.name as city, stateEntity.name as state, countryEntity.name as country
    from Urn urn
    inner join urn.city as cityEntity
    inner join urn.state as stateEntity
    inner join urn.country as countryEntity
    

    or even simpler:

    select urn.id, urn.userName, urn.city.name as city urn.state.name as state, urn.country.name as country
    from Urn urn
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I had to delete all the rows from a log table that contained about
The situation is this: a table that is used in a query (name it
Had a page that was working fine. Only change I made was to add
Had a good search here but can't see anything that gets my mind in
I had a discussion with some colleagues mentioning that there are not too many
I had the idea of a search engine that would index web items like
I have a table in my database where I store a tree structure using
I have written a table-valued UDF that starts by a CTE to return a
I am probably trying to accomplish too much in a single query, but have
I recently had a rather strange phenomenon. Had to obtain a count that included

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.