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

The Archive Base Latest Questions

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

im trying to learn some jsp as well as the spring framework. My application

  • 0

im trying to learn some jsp as well as the spring framework.

My application has 2 sql tables. ‘User’ and ‘Locations’

each Location belongs to a User. The location table has a foreign key referencing the id of the user.

I want to implement my application such that given a user (i.e ‘user1’) i can call user1.getLocations() to retrieve a list of the locations associated with that user, but i do not know where to implement this. (in the User class, on the UserDao, on the UserManager, on the controller for the page that should list all users and their , etc?)??

—-edit:
On the controller:

    List<User> users = userManager.getUsers();  
    for(User user:users) {
        user.setLocations(locationManager.getLocations(user));
    }

    myModel.put("users", users);
    return new ModelAndView("location", "model", myModel);
}

is this a conventional solution? locationManager.getLocations(user) returns a List of Locations with the same id as user.

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

    My application has 2 sql tables.
    ‘User’ and ‘Locations’

    each Location belongs to a User. The
    location table has a foreign key
    referencing the id of the user.
    I want to implement my application such that given a user (i.e ‘user1’) i can call
    user1.getLocations() to retrieve a list of the locations associated with that user
    , but i do not know where to implement this.

    I wouldn’t create a separate DAO-method for handling this, the “user1.getLocations” is the right approach. Hibernate et al. support stuff like lazy-loading and mapping of table relations as Collections (like Lists and Sets) between entities, which are meant for these kind of situations. Here’s a simple example,which might not work out-of-the-box, depending how your tables are named etc., but you’ll get the idea:

    @Entity
    public class User
    {
        @OneToMany(mappedBy="user")
        private List<Location> locations;
    
        public List<Location> getLocations()
        {           
            return locations;
        }
    }
    
    @Entity
    public class Location
    {
        @ManyToOne
        @PrimaryKeyJoinColumn
        private User user;
    
        public User getUser()
        {
            return user;
        }
    }
    

    Note that you can get the locations from the User-side, even though the relation in the database is only from Location to User (the “mappedBy”-attribute in Users’ @OneToMany actually tells which field on the “other side of the reference” (Location) points to this User).

    I’d suggest looking up some JPA and/or Hibernate with Spring -tutorials for more in-depth information.

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

Sidebar

Related Questions

I am trying to learn some of the basic and advanced features of visual
I have some javascript that I'm trying to retool using jQuery to learn the
Trying to learn some F# and I've run into a couple of hangups. Here's
I'm trying to learn some ruby. Imagine I'm looping and doing a long running
I'm trying to learn some Lisp (Common Lisp) lately, and I wonder if there
I'm trying to learn some Linq to XML stuff, and I came across the
I'm trying to learn some basic ajax using Django. My simple project is an
I am trying to learn some VB.NET for my coo-op that starts next week,
I am trying to learn some ASP.NET MVC. Please bear with me but asp.net
I am just trying to learn some Lisp, so I am going through project

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.