Possible Duplicate:
Hibernate and no PK
Anyone knows how to do hibernate mapping for table or view without a primary key?
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.
You can use JPA's @MapsId annotation to tell Hibernate that it shall use the foreign key of an associated entity as the primary key. Let's take a look at a simple example. Each Book has a Manuscript, and each Manuscript belongs to 1 Book. The foreign key of the Book is also the primary key of the Manuscript.
No. Hibernate doesn't allow to change the primary key. In general, a primary key value should never change, if needs to be changed than the primary key column(s) are not good candidate(s) for a primary key.
Don't think Hibernate allows mapping a table without a primary key...think about how Hibernate would perform updates without a column that can uniquely identify a row.
I guess a work-around would be to use a composite key with all columns, but you are much better off adding a primary key.
I would do this only when you are reading data (not writing it). When you have a DB like oracle, you can have statements like
select DOKUMENT.*, ROWID from DOKUMENT
→ and thus, you can add this statement into the Hibernate mapping:
<id column="ROWID" type="string" />
subsequently, you define all other columns as
<property...
When you use the reverse engineering Wizard, you can
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