Tables without primarys key?
"janpla" <[email protected]>
| Newsgroups | gmane.comp.java.netbeans.devel |
|---|---|
| Message-ID | <[email protected]> |
Now that I have read some more about the subject, I have found this: https://en.wikibooks.org/wiki/Java_Persistence/Identity_and_Sequencing - so, it seems that JPA does in fact require, if not actually a primary key, then some identified method of establishing a unique identity for each row. The Section "No Primary Key" suggests various wourkarounds, so this is not impossible to overcome; and apparently the ID does not actually have to be a primary key - it could be any unique key, or if none exists, the entire row. It seems to me that NetBeans could very reasonably accomodate this situation by being willing to create an Entity from the table definition, even if there is no primary key - at least in my installation, if I use @Entity on a class with no @Id, it gets flagged in the editor, so there is a clear reminder that it something to be addressed. It shouldn't be too hard to display a warning when generating the entity class along with suggestions for how to solve the problem: "You could use the following unique keys, or specify a subset of columns that are know to constitute a unique ID".