I making a sample application with Hibernate. My requirement is that there is no primary key on the table. I had to do only select query from application. I know there should be a primary key, but the table I am referring has been made without it.
It has about 50k records. So, modifying the table to add ID column does not see viable option.
Can it possible?
No, Hibernate will not work without primary key. Every table should have some unique key. The mathematical definition of a relation is a set of tuples.
Yes, hibernate requires an Id. Sometimes if you are dealing with a legacy database that for whatever reason does not have a key, you can define the key in Hibernate to be a composite key of all the columns for example, as this will be guaranteed to be unique.
Every entity in the data model must have a primary key whose values uniquely identify instances of the entity. To qualify as a primary key for an entity, an attribute must have the following properties: It must have a non-null value for each instance of the entity.
Identifiers in Hibernate represent the primary key of an entity. This implies the values are unique so that they can identify a specific entity, that they aren't null and that they won't be modified. Hibernate provides a few different ways to define identifiers.
My advice: add an autoincrement integer PK column to the table. You'll be surprised at how fast it is.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With