views:

33

answers:

1

Howto declare @Entity class for oracle table w/o PK?

I has received the error message: Column "rowid" cannot be resolved on table "LOG"

when doing mapping like this:

@Entity public class Log implements Serializable { ... @Id private ROWID rowid; ... }

A: 

Howto declare @Entity class for oracle table w/o PK?

Mapping a ROWID as Id isn't supported by standard JPA and I couldn't find any obvious proof that EclipseLink is providing an extension for this (I only found this message).

But this is not your only option and the JPA wikibook has a good paragraph about this situation:

No Primary Key

Sometimes your object or table has no primary key. The best solution in this case is normally to add a generated id to the object and table. If you do not have this option, sometimes there is a column or set of columns in the table that make up a unique value. You can use this unique set of columns as your id in JPA. The JPA Id does not always have to match the database table primary key constraint, nor is a primary key or a unique constraint required.

If your table truly has no unique columns, then use all of the columns as the id. Typically when this occurs the data is read-only, so even if the table allows duplicate rows with the same values, the objects will be the same anyway, so it does not matter that JPA thinks they are the same object. The issue with allowing updates and deletes is that there is no way to uniquely identify the object's row, so all of the matching rows will be updated or deleted.

If your object does not have an id, but its' table does, this is fine. Make the object and Embeddable object, embeddable objects do not have ids. You will need a Entity that contains this Embeddable to persist and query it.

Pascal Thivent