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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:36:18+00:00 2026-06-09T01:36:18+00:00

This seems like a common enough case, but as JPA newbie, I am having

  • 0

This seems like a common enough case, but as JPA newbie, I am having trouble figuring this out. I’m using EclipseLink and PostgreSQL, but this should relate to just the JPA spec.

I have one table PRIMARY that has an ID and then a bunch of other columns. There is another table SECONDARY that has a foreign key into the PRIMARY table also called ID. This SECONDARY table has a composite key of that ID and a varchar representing a locale.

So, in the Primary entity I want to have a field of type Map<String, Secondary> where the key is the locale string from the SECONDARY table and the entry is the Secondary entity. My Secondary class looks like this:

@Entity
public class Secondary
{
     @Id
     private Long id;
     @Id
     private String locale;
     private String str1;
     private String str2;
     .....
}

I’m thinking I want to use the @MapKeyJoinColumn annotation, but I can’t seem to get the other annotations to work. I tried this:

@OneToMany
@JoinColumn(name="ID")
@MapKeyJoinColumn(name="LOCALE")
private Map<String, Secondary> secondaryByLocale;

This resulted in it trying to select a column named secondaryByLocale_key which doesn’t exist.

I then tried this:

@OneToMany
@JoinTable(name="SECONDARY", 
        joinColumns={@JoinColumn(name="ID")},
        inverseJoinColumns=@JoinColumn(name="ID"))
@MapKeyJoinColumn(name="LOCALE")
private Map<String, Secondary> secondaryByLocale;

This results in the following error:

Exception Description: The @JoinColumns on the annotated element [field secondaryByLocale] from the entity class [class com.foo.Primary] is incomplete. When the source entity class uses a composite primary key, a @JoinColumn must be specified for each join column using the @JoinColumns. Both the name and the referencedColumnName elements must be specified in each such @JoinColumn.

I tried adding the referencedColumnName to the annotation (I wasn’t sure what it even should be), but I got the same error.

As suggested, I tried using @MapKey as follows:

@OneToMany
@JoinColumn(name="ID")
@MapKey(name="LOCALE")
private Map<String, Secondary> secondaryByLocale;

This results in the following error:

Exception Description: The map key [LOCALE] on the entity class [class com.foo.Secondary] could not be found for the mapping [org.eclipse.persistence.mappings.UnidirectionalOneToManyMapping[secondaryByLocale]].

Maybe I’m going about this all wrong, and there’s a better way to annotate the Map field. Any help would be much appreciated.

  • 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-09T01:36:20+00:00Added an answer on June 9, 2026 at 1:36 am

    Try using @MapKey(name = "locale") instead.

    @MapKeyJoinColumn is used when your map key is an entity, but here you’re just using the locale String.

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

Sidebar

Related Questions

This seems like it would be a common issue to be but I don't
This seems like a repeated question but i'm not able to get my answer.
This seems like such a simple issue but I cannot find an elegant solution.
This seems like the simplest Git question, but I can't find ANYTHING on it.
This seems like it should be relatively straightforward, I cannot figure out what I'm
This seems like a must have form input for a mobile ui framework, but
This seems like another fairly simple thing to do, but I'm again struggling on
This seems like I'm missing something obvious but I can't get redirects (>) to
This seems like it should be easy, but I can't quite find an explanation
Ok, so this seems like a common need. A little googling finds a lot

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.