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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:27:01+00:00 2026-06-09T04:27:01+00:00

I have come across some SO discussions and others posts (e.g. here , here

  • 0

I have come across some SO discussions and others posts (e.g. here, here and here) where using composite primary keys with JPA is described either as something to be avoided if possible, or as a necessity due to legacy databases or as having “hairy” corner cases. Since we are designing a new database from scratch and don’t have any legacy issues to consider is it recommended or let’s say, safer, to avoid composite primary keys with JPA (either Hibernate or EclipseLink?).

My own feeling is that since JPA engines are complex enough and certainly, like all software, not without bugs, it may be best to suffer non-normalized tables than to endure the horror of running against a bug related to composite primary keys (the rationale being that numeric single-column primary keys and foreign keys are the simplest use case for JPA engines to support and so it should be as bug-free as possible).

  • 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-09T04:27:02+00:00Added an answer on June 9, 2026 at 4:27 am

    I’ve tried both methods, and personally I prefer avoiding composite primary keys for several reasons:

    • You can make a superclass containing the id field, so you don’t have to bother with it in all your entities.
    • Entity creation becomes much easier
    • JPA plays nicer in general
    • Referencing to an entity becomes easier. For example storing a bunch of IDs in a set, or specififying a single id in the query string of a web page is largelly simplified by only having to use a single number.
    • You can use a single equals method specified in the super class that works for all entities).
    • If you use JSF you can make a generic converter
    • Easier to specify objects when working with your DB client

    But it brings some bad parts aswell:

    • Small amount of denormalization
    • Working with unpersisted objects (if you use auto generated IDs, which you should) can mean trouble in some cases, since equality methods and such needs an ID to work correctly
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have come across with this syntax while reading some others code Map<String, String>
Recently when I come across some slow queries, I have seen this Using sort_union(sourceClass,destinationClass)
I thought i'd try out some WPF Metro using Mahapps.Metro and have come across
I have come across some strange behaviour, and I'm assuming a bug in Firefox,
Hi i have come across some urls of the type http://localhost/jsfweb/cat/query/ where query is
I'm currently porting my GAE app to Python 2.7 and have come across some
I have come across an annoying problem while writing some PHP4 code. I renamed
I have taken over some code from a previous developer and have come across
I'm moving some code from Microsoft.Practices.EnterpriseLibrary.Validation.Validators to System.ComponentModel.DataAnnotations, and have come across a more
I am debugging some programs. In per-instruction debugging (Eclipse CDT), I have come across

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.