chip
chip

Reputation: 3279

how to deal with entities that don't need @id annotations

I have some classes up in the schema, some of them are tables that don't have any ids because they are used as reference/value tables like country, gender, civil status and etc. but when I try to run the application, the application server glassfish won't deploy it because it is asking for a field with an @Id attribute on my entities which it don't normally have because it is mainly used as a values table.

other than creating an id field, what else can I do?

Upvotes: 0

Views: 211

Answers (2)

axtavt
axtavt

Reputation: 242686

@Id is used to mark a primary key. Usually it's a surrogate primary key (i.e., an arbitrary number identifying a row), but it can be a natural primary key as well (i.e. any column used to reference rows of that table from the outside).

In your case these reference tables certainly have primary keys, and you need to annotate corresponding fields with @Id.

Upvotes: 0

DataNucleus
DataNucleus

Reputation: 15577

JPA doesn't do entities with no identity; JDO is the only Java persistence specification to support that concept.

With JPA one way would be to add an arbitrary id (if one of the columns is unique then fine, otherwise add a new (dummy) column to store the "id"

Upvotes: 1

Related Questions