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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:41:19+00:00 2026-06-06T11:41:19+00:00

I have a problem and I just do not know how to solve it.

  • 0

I have a problem and I just do not know how to solve it.
I want to model in JAVA a structure like: Companies, Events and Locations.

  • Each Company includes one or many Location/s which represents the places where a branch of the company is
  • Each event also has a Location where the event takes place

Here’s the code:

public class Event {
    int id;
    String name;
    Location location;
    ...
}

public class Location {
    int id;
    String name;
    String building;
    ...
}

public class Company {
    int id;
    String name;
    Collection<Location> locations;
    ...
}

My problem is that i want to use ORMLite for saving the objects in a Database. But if I understood the foreign things in ORMLite correctly, i have to add a Company instance variable to the Location:

public class Location {
  @DatabaseField(columnName = "com_id", foreign = true)
  Company company;
  @DatabaseField(id = true, columnName = "loc_id")
  int id;
  @DatabaseField(columnName = "loc_name")
  String name;
  @DatabaseField(columnName = "loc_build")
  String building;
  ...
}

public class Company {
  @DatabaseField(columnName = "com_id")
  int id;
  @DatabaseField(columnName = "com_name")
  String name;
  @ForeignCollectionField()
  Collection<Location> locations;
  ...
}

But now the Location doesn’t work for the Events!?! How can I implement such a behaviour?

Thank you for your answers

  • 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-06-06T11:41:20+00:00Added an answer on June 6, 2026 at 11:41 am

    Somehow you need to assign “ownership” of a Location by a Company. You can do this in (at least) 2 different ways.

    1. As you mentioned, you can have a Location has a Company field. This would work fine if there was a one-to-one relationship there. It would not work if you are trying to have one "Pittsburgh" Location and you want both "Alcoa" and "US Steel" companies having a location in Pittsburgh.

    2. The 2nd way to implement it is to have a CompanyLocation entity which is often called a join-table in ORM languages. ORMLite does not make this join table for you however.

      public class CompanyLocation {
         @DatabaseField(foreign = true)
         Company company;
         @DatabaseField(foreign = true)
         Location location;
      }
      

      So if want "Alcoa" to have a Location of "Pittsburgh" you need to insert a CompanyLocation into the table which defines the relationship.

    Hope this helps.

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

Sidebar

Related Questions

I have a problem that I have not managed to solve. I developed a
I just encountered with a problem that I don't know how to solve. It
i have no idea how to solve a problem with sending $_POST. I want
I know about the svn:ignore property, but that doesn't solve my problem. I have
i have a problem just as title, and the http-status is 302 Moved Temporarily.
I have the problem I just installed the new Monodevelop 2.2.2 on Windows but
I have this problem and i just cannot find a solution to it. I
I just started a graphical C++ course and I have problem getting an overview
I have tried troubleshooting this problem and just ended up with nothing, I hope
I don't have a problem, I'm just curious. Here is a part of my

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.