Matt
Matt

Reputation: 1691

How to know a entity is going to insert or update

Because of some limitation, client asked that I can't use incremental "id" primary key, only compound primary key is allowed. And I can't use JPA annotation to have entity callback. Thus how can I know an entity is going to be inserted or updated ? thanks a lot.

Upvotes: 1

Views: 550

Answers (1)

Arthur Ronald
Arthur Ronald

Reputation: 33785

Use a version column

@Version
public Integer getVersion() {
    return this.version;
}

Whether it is null so it is an insert else it is an update.

regards,

Upvotes: 1

Related Questions