Is it possible to create a table (from a JPA annotated Hibernate @Entity) that does not contain a primary key / Id?
I know this is not a good idea; a table should have a primary key.
Is it possible to create a table (from a JPA annotated Hibernate @Entity) that does not contain a primary key / Id?
I know this is not a good idea; a table should have a primary key.
I found that its not possible to do so. So bad luck for those working with legacy systems.
If you reverse engineer (create JPA annotated entities from existing JDBC connection) the table will create two Java classes, one Entity and with one field; id, and one embeddable id containing all the columns from your relation.
Though ROWID is a pseudo-column,yet as ROWID corresponds to the physical address of a ROW, it is the quickest mean to retrieve any row data. As @Id is used to identify the object uniquely and ROWID is unique inside a table, we can exploit it to overcome the issue we are discussing about. Actually, if we don't need any meaningful unique identifier, ROWID is the best column to annotate with @Id annotation as it corresponds to the physical address of the row. The following code worked for me.
@Id
@Column(name = "ROWID")
private String Id;