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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:44:02+00:00 2026-05-31T11:44:02+00:00

I know, @SecondaryTable issues were published numerous times, so, if there is the same

  • 0

I know, @SecondaryTable issues were published numerous times, so, if there is the same one (I haven’t found it yet), please, give me the link or an advice.

I have two tables in my database (firstTable and secondTable), two POJO Hibernate classes (FirstTablePojo and SecondTablePojo).

+----------+             +-----------+
|firstTable|             |secondTable|
|----------+             |-----------+
|featureId |------------>|featureId  |(secondTable's primary key)
|foo       |             |featureName|
|bar       |             +-----------+
+----------+

I want to show fields from both these tables in the jsp from the single list object, I decided to use @SecondaryTable. These two tables are connected by the featureId field (which is a primary key for the secondTable), I want the featureName from the secondTable to be shown along with fields from the firstTable. The FirstTablePojo is preceded by this annotation:

@SecondaryTable(name="secondTable", 
    pkJoinColumns=@PrimaryKeyJoinColumn(name="featureId", 
                                        referencedColumnName = "featureId"))

I added this property to the FirstTablePojo (with getters and setters):

 @ManyToOne
 @JoinColumn(name="featureId", table="secondTable")
 String featureName;

When with a help of <c:forEach items="${features}" var="feature">, I get each ${feature.foo} (foo is a property that was in the FirstTablePojo before I used @SecondaryTable) and ${feature.featureName}, I see each foo, but none of the featureNames appear. It’d be great if someone could tell me what do I miss here and why feature’s names from the other table do not appear in the list of FirstTablePojo objects.

  • 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-31T11:44:03+00:00Added an answer on May 31, 2026 at 11:44 am

    The point of the @SecondaryTable annotation is to map the fields of a single entity to several tables, exactly as if those tables were merged into a single one.

    @ManyToOne is used to map a many-to-one association betwen two entities. But you just have one. It makes no sense in this context. And @JoinColumn is used to indicate that a field is mapped to a column that constitutes a … join column, i.e. a foreign key to another table. So it doesn’t make sense either.

    Just use the following mapping:

    @Column(name="featureName", table="secondTable")
    String featureName;
    

    This is well explained, with an example, in the Hibernate documentation.

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

Sidebar

Related Questions

I know this has been asked many times but i'm yet to find a
Know of an OCAML/CAML IDE? Especially one that runs on Linux?
I know this might be a no-brainer, but please read on. I also know
I know very little about Agile but I wonder if there is any difference
I know there are similar questions already on SO but none of them seem
I know of cufon and one other similar. But what is the best way
I know this is a very simple question for you experts,but please forgive me.Im
I know that there's something fishy about the malloc part, but I'm having trouble
i know there are several questions about regex recursion in .net. I can write
I know that this may be common knowledge, but is there a way to

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.