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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:30:11+00:00 2026-05-27T04:30:11+00:00

Need some help understanding if I’m on the right track here and exactly what

  • 0

Need some help understanding if I’m on the right track here and exactly what I need to do. Hope someone can chime in.

So I’ve got three tables, Job, Authorization, and Filter. Each Job must have one Authorization and one Filter. Of course, each Filter could be used by more than one job and the same goes for the Authorization. However, the Filters and Authorizations don’t need to know what Jobs they are being used by.

So that is a one to many relationship on the part of the Filters and Authorizations I believe right? Or am I off track? How is this modeled in a database? I believe the Job table needs to have a foreign key field to the Filter and Authorization tables. Do the Filter and Authorization tables need foreign key fields themselves to Job?

Next, how do I model this in Java objects and then how do I set up the hibernate or java persistence annotations? I believe the Filter class looks like:

class Filter {

    @OnetoMany
    @JoinColumn(name="filterID")
    private Job job;
}

and the Authorization class basically the same and then how would the Job class look? The thing that’s really throwing me is that the Filter and Authorization classes don’t need any knowledge of what Job they’re associated with so I don’t see the need for them to actually hold references to Job objects. Only the Job class needs to hold references to the Filter and Authorization objects. So do I really need the above code?

I’m hoping someone can help clarify all this for me as I can’t seem to wrap my head around it. Databases are not my strong suit. Thanks.

  • 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-27T04:30:12+00:00Added an answer on May 27, 2026 at 4:30 am

    As far as I know, using a @OneToMany annotation is not very recommended in your situation. Maybe you may want the other side to own the relation.

    Check this article out:
    http://josian.wordpress.com/2006/09/09/hibernate-annotations-bidirectional-one-to-many/

    So, to your question, no, you do not need the above code.

    You need something like this:

    class Job {
    
        @Id
        //stuff...
    
    
        @ManyToOne(fetch=FetchType.LAZY)
        @JoinColumn (name="authorization_id", nullable = false, updatable = false, insertable = false)
        private Authorization authorization;
    
        @ManyToOne(fetch=FetchType.LAZY)
        @JoinColumn (name="filter_id", nullable = false, updatable = false, insertable = false)
        private Filter filter;
    }
    

    and on your Filter

    @Entity
    @Table(name="filter")
    class Filter {
    
          //some stuff, but no relation!
    }
    

    EDIT:
    The @JoinColumn is just the name you want to appear in your Job table. By default, if you dont specify the join çolumn name, it is going to be {foreignTableName}_id. In the case of Authorizatrion, if you annotated it like this:

    @Entity
    @Table(name="foo")
    class Authorization{
     @Id
     @column(name="auth_id")
     private Long authId;
    }
    

    the default join column generated for you in the Job table will be

    "foo_id" and will reference the

    "auth_id" field in the

    "foo" table.

    TO your final comment:

    Actually you don’t need to put foreign keys in the db. In the Job Entity, the

    @ManyToOne annotation already ensures the keys will be placed for you. The

    @JoinColumn specifies the names of the foreign key. For example, if you want your foreign key name in the Job table to Authorization to be called ‘authorization_fk’, you would use

    @JoinColumn('authorization_fk')

    and this is how it is gonna be placed in your Job table.

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

Sidebar

Related Questions

I need some advice here, I hope somebody can help me. I have the
I need some help understanding what's happening here. This code is from a models/log.py
i need some help understanding how i can create a new custom event. i
I need some help understanding this bit of code pre { white-space: pre; white-space:
I need help understanding some C++ operator overload statements. The class is declared like
Need some help understanding why my concat() is failing and how to fix it.
I need some help understanding some of the points from Paul Graham’s What Made
I need some help understanding the correct way to mix variables with strings like
I need some help understanding how stdext::hash_multimap's lower_bound, upper_bound and equal_range work (at least
I'm new to ORM stuff and I need some help understanding something. Let's assume

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.