Hibernate without Primary Key

  1. Hibernate requires that entity tables have primary keys. End of story.
  2. 50k records is simply not that many when you're talking about a database.

My advice: add an autoincrement integer PK column to the table. You'll be surprised at how fast it is.


So, modifying the table to add ID column does not see viable option.

Why's that? Do you just mean, because it already has fifty thousand records? Trust me, that's really not very many.


Even if the table doesn't have a surrogate key, and doesn't have a primary-key constraint, and even if you're not willing to alter the table, it still probably has some sort of candidate key — that is, some set of columns that are never null, and whose values uniquely identify a record. Even without altering the table to enforce their uniqueness and non-nullity, you can tell Hibernate that those columns form a composite ID.

Tags:

Hibernate