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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:19:02+00:00 2026-05-23T02:19:02+00:00

Hullo, So… I have the following objects: public class Person { // some other

  • 0

Hullo,
So… I have the following objects:

public class Person {
   // some other getters/setters omitted.
   void setAddress(Address addy) {
       // omitted
   }

   Address getAddress() {
       // omitted
   }
}

public class Address {
   Integer getId() {
      // omitted
   }
}

And, I have the following hibernate mappings:

<class name="Person">
    <id name="id" column="personId">
        <generator class="native"/>
    </id>

    <many-to-one name="address" 
        column="addressId" 
        unique="true"
        not-null="true"/>
</class>

<class name="Address">
    <id name="id" column="addressId">
        <generator class="native"/>
    </id>
</class>

So, there is a one to one mapping from Person to Address, Person has the foreign key to Address.


What I’m trying to do is fetch a Person object from a given Address ID… but I can’t seem to figure out the correct HQL syntax:

public Person getPersonFromAddress(Address address) {

    Query query = this.session.createQuery("select p from Person as p where p.address_id = " + address.getId());

    @SuppressWarnings("unchecked")
    Person p = (Person)query.uniqueResult();

    return p;
}

I know I don’t have a mapping from the foreign key column to a property on Person. Everytime I try to add one I get an exception saying I’m using the same column twice? I don’t see what would be wrong with that :).

Anyways, what would be the best way to fetch the Person given an Address? Any help would be appreciated.

  • 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-23T02:19:03+00:00Added an answer on May 23, 2026 at 2:19 am

    You should be able to do this

    Query query = this.session.createQuery("select p from Person as p where p.address=:address")
                .setParameter("address",address); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this class: class TestClass { var $testvar; public function __construct() { $this->$testvar
Hullo, For example if I had: public class Fu { int _bar; public Fu(){
Hello I have the following error by git-fsck, which cannot be cleaned by git-gc
Hello again ladies and gents! OK, following on from my other question on ASP.NET
Hullo, I have an activity whose layout is made of a single FrameLayout. I
Hullo, For some reason (that I can't work out) a function that returns an
Hello i have tableview with many objects in it. If i want to add
Hello i'm trying to implement an AsynController, here is my code: [NoCache] public class
Hello i have the following problem, I record a video using red5 like this:
Hullo all, Wondering if there are any Java hackers who can clue me in

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.