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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:38:56+00:00 2026-06-09T21:38:56+00:00

I got two classes: Forum and Topic . I previously told I should have

  • 0

I got two classes: Forum and Topic.
I previously told I should have Forum attribute (in Topic), something like that:

@ManyToOne
@JoinColumn(name = “forum”)
protected Forum forum;

instead of just keeping the id of the forum.
I saw that in postgresql the Forum attribute saved as “bigint” (the forum id)
so what’s the point of holding the Forum reference anyway?

  • 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-09T21:38:57+00:00Added an answer on June 9, 2026 at 9:38 pm

    This is exactly why you use a object relational mapping (ORM) solution (here JPA). The problem is: you can’t really put references into your database, but in your code, it’s so much better to have references than plain ids. JPA does this for you. You can create a topic, set it’s forum attribute, to a forum object and JPA takes care of the insertion to the database (you don’t have to get the id attribute of the forum, then insert it by hand with an sql statement).

    Consider this:

    Forum f1 = new Forum();
    Topic t1 = new Topic();
    t1.forum = f1;
    t1.forum.someMethod();
    

    Simply you can navigate backwards from topic to the forum, and call the forum’s method. This reference is better than having an id there:

    t1.forumId = f1.id;
    //to navigate back without having f1 in your scope:
    Forum f2 = entityManager.find(Forum.class, t1.forumId);
    f2.someMethod();
    

    Here you had to find the forum associated with the topic as you only had an id. Much worse.

    Simply put: you can easily navigate backwards (from topic to forum) in your java code, so you have a reference in your Topic class, but this can only be represented in sql as a foreign key.

    ps: to be more precise JPA is an interface, the implementation used by you (eg. Hibernate, EclipseLink) is the ORM solution which does the work.

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

Sidebar

Related Questions

Lets put the case that we've got two separate classes, each owns a mysqli
I've got a UITableViewController subclass that is subclassed by two other classes. In some
I've got two classes: a template class, and a regular class that inherits from
I have got two classes, one a subclass of the other (say Animal and
I have two classes and an interface like interface IVehicle { void Drive(); }
I have a console application that i got to make and i would like
I have got two classes class Claim include Mongoid::Document embeds_many :claim_fields belongs_to :user ...
I've got two classes (Students and Courses) which have a many-to-many-relationship. Instances of them
I've got an interface that two classes implement at the moment. The data for
We have two classes that have the exact same public accessors (and many of

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.